• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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: 951
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: 23840
141
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.

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: 65457
248
  • 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);
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!