Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
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: 954
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
Posts: 23877
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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.

https://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: 69426
276
  • 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);
 
Normally trees don't drive trucks. Does this tiny ad have a license?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic