• Post Reply Bookmark Topic Watch Topic
  • New Topic

how should i run (printEmployee) mtethod inside main method??  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


package com.example;

import com.example.domain.Admin;
import com.example.domain.Director;
import com.example.domain.Employee;
import com.example.domain.Engineer;
import com.example.domain.Manager;



public class EmployeeTest {

/**
*
* @param args
*/
public static void main(String[] args) {

Employee emp = new Employee(2, "asdddfffg", "123_32_45", 345_54.09);

emp.setName("ghghjgjg");


Engineer eng = new Engineer(1, "jane", "123", 45.27, "cse");


Manager mgr = new Manager(204, "barbara jhonson", "054-12-1818", 109_501.36, "us digital marketing");
mgr.raiseSalary(1000.0);

Admin adm = new Admin(304, "abcd", "125_45_78", 108_501.36, "cse");

Director dir = new Director(308, "wert", "12_87_64", 200_458.98, "cse", 18_78.59);




/**
* @param emp
*
*/

System.out.println(emp);


/**
* @param eng
*/

System.out.println();
System.out.println("Enigineer id:" + eng.getEmpId());
System.out.println("Enigineer Name:" + eng.getName());
System.out.println("EnigineerSSN" + eng.getSsn());
System.out.println("Enigineer salary" + eng.getSalary());
System.out.println("Enigineer department" + eng.getDeptName());


/**
*
* @param adm
*/

System.out.println();
System.out.println("Employee id:" + adm.getEmpId());
System.out.println("Employee Name:" + adm.getName());
System.out.println("Employee SSN" + adm.getSsn());
System.out.println("Employee salary" + adm.getSalary());
System.out.println("Employee department" + adm.getDeptName());


/**
*
* @param mgr
*/

System.out.println();
System.out.println("Employee id:" + mgr.getEmpId());
System.out.println("Employee Name:" + mgr.getName());
System.out.println("Employee SSN" + mgr.getSsn());
System.out.println("Employee salary" + mgr.getSalary());
System.out.println("Employee department" + mgr.getDeptName());



/**
*
* @param dir
*/

System.out.println("");
System.out.println("Employee id:" + dir.getEmpId());
System.out.println("Employee Name:" + dir.getName());
System.out.println("Employee SSN" + dir.getSsn());
System.out.println("Employee salary" + dir.getSalary());
System.out.println("Employee budget" + dir.getBudget());

/**
*
* @param emp
*/

public static void printEmployee(Employee emp){
System.out.println("");
System.out.println("Employee id:" + emp.getEmpId());
System.out.println("Employee Name:" + emp.getName());
System.out.println("Employee SSN" + emp.getSsn());
System.out.println("Employee salary" + emp.getSalary());


}


}




}
 
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags for better understanding...

Are you able to compile your code? You have written printEmployee method inside main.
 
nikhil saini
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to use code tags??

when I am compiling this code it giving me an error on print employee method that illegal start of expression
I want to run this print employee method inside main.
but its not running showing this Run time exception.?? illegal start of expression

please help me out
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nikhil saini wrote:
I want to run this print employee method inside main.
but its not running showing this Run time exception.?? illegal start of expression


Your cut-n-paste of code has created a situation, similar to your other topic.

http://www.coderanch.com/t/649493/java/java/illegal-start-expression

You need to make sure that you don't wind up declaring a method inside another method.

Henry
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It tells you how to use code tags here.

you should not be printing all those attributes of the Employee objects separately. You should give the Employee class an overridden toString method then you simply write
System.out.println(myEmployee);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!