I've had to write a class on my own, which I have, and then I need to apply it to another program that creates three objects that holds specific data. The class seems right to me, it holds spots for an Employee name, Employee Idnumber, the department and position of the employee as well.
The second half of this question asks me to plug in specific information into three objects in a separate program. For instance, 1 employee will be Susan Meyers. Their IDnumber will be 47899. Their department is Accounting. Their position is Vice President.
Having a brain fart right now on how to go about this. Any help would be appreciated, specifically an example on how to accomplish the above one so I can finish the others confidently.
Below is the class I wrote first.
public class Employee { //Fields private String name; //Employees name private int idnumber; //Employees ID number private String department; //Department the employee works at private String position; //Employees position //Constructor public Employee(String nam, int idnum, String dep, String pos) { name = nam; idnumber = idnum; department = dep; position = pos; } //The setname that accepts argument for employees name public void setName(String nam) { name = nam; } //The setIdnumber accepts argument for employees id number public void setIdnumber(int idnum) { idnumber = idnum; } //The setDepartment accepts argument for employees department public void setDepartment(String dep) { department = dep; } //The setPosition accepts argument for employees position public void setPosition(String pos) { position = pos; } //The getName method returns the name of the employee public String getName() { return name; } //The getIdnumber method returns the employees ID number public int getIdnumber() { return idnumber; } //The getDepartment method returns the employees department name public String getDepartment() { return department; } //The getPosition method returns the employees position public String getPosition() { return position; } }
I started coding and this is what direction I was heading
import java.util.Scanner; public class EmployeeTest { public static void main(String[] args) { String testName1; //Holds employee names int testIdnumber1; //Holds employee idnumbers String testDepartment1; //Holds employee departments String testPosition1; // Holds employee positions //Creates a Scanner object for keyboard input Scanner keyword = new Scanner(System.in); testName1 = ("Susan Meyers"); System.out.println(testName1); } }
I was going to do this for each one, but it doesn't seem very efficient? Is there an easier or cleaner way to do this?