java - Using an object and accessor methods -
alright, created seperate class has accessor , mutator methods, constructors, etc etc. compiles fine no problem.
now have demo class supposed use information other class produce result. simple enough, i'm getting errors. think problem may simple cant figure out.
heres errors:
employeedemowilson.java:19: error: ')' expected system.out.println("employee id number " + emp1.getidnumber() + " " emp1.getname() + ". susan " emp1.getposition() ^ employeedemowilson.java:19: error: illegal start of expression system.out.println("employee id number " + emp1.getidnumber() + " " emp1.getname() + ". susan " emp1.getposition() ^ employeedemowilson.java:19: error: ';' expected system.out.println("employee id number " + emp1.getidnumber() + " " emp1.getname() + ". susan " emp1.getposition() ^ employeedemowilson.java:20: error: not statement + " of " + emp1.getdepartment() + " department."); ^ employeedemowilson.java:20: error: ';' expected + " of " + emp1.getdepartment() + " department."); ^ 5 errors heres code in error coming from:
public class employeedemo { public static void main (string [] args) { // creating employee objects. employee emp1 = new employee("susan meyers", 47899, "accounting", "vice president"); employee emp2 = new employee("mark jones", 39119, "it", "programmer"); employee emp3 = new employee("joy rogers", 81774, "manufacturing", "engineer"); //displayng employee information. system.out.println("employee id number " + emp1.getidnumber() + " " emp1.getname() + ". susan " emp1.getposition() + " of " + emp1.getdepartment() + " department."); } } heres original class has constructors, methods , , forth. compiles fine.
public class employee { // reference string object holds employee's name private string name; // int variable holds employee's id number private int idnumber; // reference string object holds department in employee works. private string department; // reference string object holds job title of employee. private string position; /** constructor @param name name of employee. @param idnumber id number of employee. @param department department employee belongs to. @param position job title of employee. */ public employee(string name, int idnumber, string department, string position) { this.name = name; this.idnumber = idnumber; this.department = department; this.position = position; } /** constructor 2 @param name name of employee. @param idnumber id number of employee. */ public employee(string name, int idnumber) { this.name = name; this.idnumber = idnumber; department = ""; position = ""; } /** constructor 3 */ public employee() { name = ""; idnumber = 0; department = ""; position = ""; } /** sets name field. @param empn employee's name. */ public string setname(string empn) { return name = empn; } /** sets idnumber field. @param idn employee's id number. */ public int setidnumber(int idn) { return idnumber = idn; } /** sets department field. @param dept department employee belongs to. */ public string setdepartment(string dept) { return department = dept; } /** sets position field. @param pos job title employee holds. */ public string setposition(string pos) { return position = pos; } /** gets name of employee. @return employee's name. */ public string getname() { return name; } /** gets id number of employee. @return employee's id number. */ public int getidnumber() { return idnumber; } /** gets department employee belongs to. @return department employee belongs to. */ public string getdepartment() { return department; } /** gets position employee has. @return job title employee holds. */ public string getposition() { return position; } }
you're missing few + concatenation operators in concatenated string. change
system.out.println("employee id number " + emp1.getidnumber() + " " emp1.getname() + ". susan " emp1.getposition() + " of " + emp1.getdepartment() + " department."); to
// here system.out.println("employee id number " + emp1.getidnumber() + " " + emp1.getname() // , here + ". susan " + emp1.getposition() + " of " + emp1.getdepartment() + " department.");
Comments
Post a Comment