Start New Discussion within our Software Development Community

How do I set a new salary and a new department for the emp1 object class using a setPosition method. Everything works except that for some reason I just can't show the results on Message.
Here is the Driver:

import javax.swing.JOptionPane;
public class Employee
{
public static void main(String[] args)
{
Employees emp1 = new Employees();
Employees emp2 = new Employees("Management", 3.7);
Employees emp3 = new Employees(" Sales " , 8.0);


JOptionPane.showMessageDialog(null, "Here are 3
employees: " +                              "\nPosition: " + emp1.getDept() +
"\nSalary: " + emp1.getSalary() +
"\nPosition: " + emp2.getDept() +
"\nSalary: " + emp2.getSalary() +
"\nPosition: " + emp3.getDept() +
"\nSalary: " + emp3.getSalary(),
"Message",
JOptionPane.INFORMATION_MESSAGE);


JOptionPane.showInputDialog(null,"Set Emp #1" + "\nPosition: " + emp1.setDept()  );


JOptionPane.showInputDialog(null,"Set Emp #1 " + "\nSalary" + emp1.setSalary());


JOptionPane.showMessageDialog(null, "Here is Employee #1: " +
"\nPosition: " + emp1.getDept() +
"\nSalary: " + emp1.getSalary
(),"Message",JOptionPane.INFORMATION_MESSAGE);



}



}
Here is the class:


public class Employees
{
private String department;
private double salary;
public Employees ()
{
department = "unknown";
}
public Employees (String newDept, double newSalary)
{
department = newDept;
salary =  newSalary;
}



public String getDept()
{
return department;
}
public double getSalary()
{
return salary;
}


public void setSalary(double newSalary)
{


salary = newSalary;
}
public String setDept() {


return department;
}
public double setSalary() {


return salary;
}


public String toString()
{
return ("Dept:" + department + "; \nSalary:" + salary);


}


}

1) Create a setPosition method that has a parameter of an Employee object and parameters of the new values.

This article has been dead for over six months. Start a new discussion instead.