Question: Ask the user for three employees. Store the data into three employee objects (use the Employee class from the previous question). Display those employees in
Ask the user for three employees. Store the data into three employee objects (use the Employee class from the previous question). Display those employees in a table. On this question, you'll submit two files: Employee.java and some other file that has a main.
these are my files, but I can't get them to be properly aligned. help please!
Employee.java:
public class Employee { private String name; private int id; private String department; private String position; public Employee() { } public Employee(String name, int id, String department, String position) { this.name = name; this.id = id; this.department = department; this.position = position; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } public String getPosition() { return position; } public void setPosition(String position) { this.position = position; } public String toString() { return "Employee [name=" + name + ", id=" + id + ", department=" + department + ", position=" + position + "]"; } } Main.java:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String name,department,position; int id; System.out.println("-- Employee Entry Form --"); System.out.println("Enter name"); name = sc.nextLine(); System.out.println("Enter ID"); id = sc.nextInt(); sc.nextLine(); System.out.println("Enter department"); department = sc.nextLine(); System.out.println("Enter position"); position = sc.nextLine(); Employee emp1 = new Employee(name,id,department,position); System.out.println("-- Employee Entry Form --"); System.out.println("Enter name"); name = sc.nextLine(); System.out.println("Enter ID"); id = sc.nextInt(); sc.nextLine(); System.out.println("Enter department"); department = sc.nextLine(); System.out.println("Enter position"); position = sc.nextLine(); Employee emp2 = new Employee(name,id,department,position); System.out.println("-- Employee Entry Form --"); System.out.println("Enter name"); name = sc.nextLine(); System.out.println("Enter ID"); id = sc.nextInt(); sc.nextLine(); System.out.println("Enter department"); department = sc.nextLine(); System.out.println("Enter position"); position = sc.nextLine(); Employee emp3 = new Employee(name,id,department,position); System.out.printf("%15s%15s%15s%15s ","Name","ID","Department","Position"); System.out.printf("%15s%15d%15s%15s ",emp1.getName(),emp1.getId(),emp1.getDepartment(),emp1.getPosition()); System.out.printf("%15s%15d%15s%15s ",emp2.getName(),emp2.getId(),emp2.getDepartment(),emp2.getPosition()); System.out.printf("%15s%15d%15s%15s ",emp3.getName(),emp3.getId(),emp3.getDepartment(),emp3.getPosition()); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
