Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

All of code must be commented out Create a Java application, that support the fo

ID: 3804002 • Letter: A

Question

All of code must be commented out

Create a Java application, that support the following:

Create an Employee class, which holds following information:

Employee First Name

Employee Last Name

Employee Phone Number

Employee Address

Employee id

Employee Title

Employee salary

Create an application that uses the Employee class

Constructors –Getters and setters

A minimum of 3 constructors including default constructor

equals() method

Helper methods

toString() method

Create an array of 5 Employee objects

Use a Scanner to read in 5 employee information

Change 2 employees information (3-items each)

Create an Employee report at the end using appropriate class methods, to generate the report

Explanation / Answer

Employee.java

public class Employee {
   //Declaring instance variables
   private String firstname;
   private String lastName;
   private String phone_number;
   private String address;
   private int id;
   private String title;
   private double salary;
  
   //Default constructor
   public Employee() {
   }
  
   //Parameterized constructor
   public Employee(String firstname, String lastName, String phone_number,
           int id, double salary) {
       this.firstname = firstname;
       this.lastName = lastName;
       this.phone_number = phone_number;
       this.id = id;
       this.salary = salary;
   }
  
   //Parameterized constructor
   public Employee(String firstname, String lastName, String phone_number,
           String address, int id, String title, double salary) {
       this.firstname = firstname;
       this.lastName = lastName;
       this.phone_number = phone_number;
       this.address = address;
       this.id = id;
       this.title = title;
       this.salary = salary;
   }

   //Setters and getters
   public String getFirstname() {
       return firstname;
   }

   public void setFirstname(String firstname) {
       this.firstname = firstname;
   }

   public String getLastName() {
       return lastName;
   }

   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   public String getPhone_number() {
       return phone_number;
   }

   public void setPhone_number(String phone_number) {
       this.phone_number = phone_number;
   }

   public String getAddress() {
       return address;
   }

   public void setAddress(String address) {
       this.address = address;
   }

   public int getId() {
       return id;
   }

   public void setId(int id) {
       this.id = id;
   }

   public String getTitle() {
       return title;
   }

   public void setTitle(String title) {
       this.title = title;
   }

   public double getSalary() {
       return salary;
   }

   public void setSalary(double salary) {
       this.salary = salary;
   }


   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Employee other = (Employee) obj;
       if (address == null) {
           if (other.address != null)
               return false;
       } else if (!address.equals(other.address))
           return false;
       if (firstname == null) {
           if (other.firstname != null)
               return false;
       } else if (!firstname.equals(other.firstname))
           return false;
       if (id != other.id)
           return false;
       if (lastName == null) {
           if (other.lastName != null)
               return false;
       } else if (!lastName.equals(other.lastName))
           return false;
       if (phone_number == null) {
           if (other.phone_number != null)
               return false;
       } else if (!phone_number.equals(other.phone_number))
           return false;
       if (Double.doubleToLongBits(salary) != Double
               .doubleToLongBits(other.salary))
           return false;
       if (title == null) {
           if (other.title != null)
               return false;
       } else if (!title.equals(other.title))
           return false;
       return true;
   }

   /* toString method is used to display
   * the contents of an object inside it
   */
   @Override
   public String toString() {
       return "First Name=" + firstname + ", Last Name=" + lastName
               + ", Phone Number=" + phone_number + ", Address=" + address
               + ", Id=" + id + ", Title=" + title + ", Salary=" + salary;
   }
     

}

____________________

Test.java

import java.util.Scanner;

public class Test {

   public static void main(String[] args) {
       //Declaring variables
       String firstname;
       String lastname;
   String phoneNumber;
       String address;
       int id;
       String title;
       double salary;
      
       //Scanner object is used to get the inputs entered by the user
               Scanner sc=new Scanner(System.in);
              
       //Employee array of size 5      
       Employee[] e=new Employee[5];
      
       //Getting the inputs entered by the user
       for(int i=0;i<5;i++)
       {
           System.out.println(" Employee "+(i+1)+" Info :");
           System.out.print("Enter firstname :");
           firstname=sc.next();
           System.out.print("Enter lastname :");
           lastname=sc.next();
           System.out.print("Enter phone no :");
           phoneNumber=sc.next();
           sc.nextLine();
           System.out.print("Enter Address : ");
           address=sc.nextLine();
           System.out.print("Enter id :");
           id=sc.nextInt();
           System.out.print("Enter title :");
           title=sc.next();
           System.out.print("Enter Salary :");
           salary=sc.nextDouble();
           e[i]=new Employee(firstname, lastname, phoneNumber, address, id, title, salary);
          
       }
  
       //Displaying the employees info
       for(int i=0;i<e.length;i++)
           System.out.println("Employee "+(i+1)+"info :"+e[i].toString());
      
       //Modifying the data
   e[0].setLastName("Kane");
   e[0].setPhone_number("9876543218");
   e[0].setSalary(89000.00);
     
   e[3].setLastName("Hayes");
   e[3].setPhone_number("9665544332");
   e[3].setSalary(97000.00);
     
   System.out.println();
     
   //Displaying the data
       for(int i=0;i<e.length;i++)
           System.out.println("Employee "+(i+1)+" info :"+e[i].toString());
     

   }

}

_____________________

Output:


Employee 1 Info :
Enter firstname :Williams
Enter lastname :Jones
Enter phone no :9887766543
Enter Address : 101,Park Street
Enter id :1234
Enter title :Manager
Enter Salary :56000.00

Employee 2 Info :
Enter firstname :Micheal
Enter lastname :John
Enter phone no :9881245678
Enter Address : 105,Church Street
Enter id :3456
Enter title :Supervisor
Enter Salary :56000.00

Employee 3 Info :
Enter firstname :Sachin
Enter lastname :Tendulkar
Enter phone no :9456781234
Enter Address : 303,Lake Road
Enter id :6789
Enter title :Manager
Enter Salary :67000.00

Employee 4 Info :
Enter firstname :Ricky
Enter lastname :Pointing
Enter phone no :9887761234
Enter Address : 505,Park Street
Enter id :5690
Enter title :Manager
Enter Salary :90000.00

Employee 5 Info :
Enter firstname :Pat
Enter lastname :Simkox
Enter phone no :9123456783
Enter Address : 405,James Street
Enter id :5423
Enter title :Supervisor
Enter Salary :78000.00
Employee Info #
First Name=Williams,
Last Name=Jones,
Phone Number=9887766543,
Address=101,Park Street,
Id=1234,
Title=Manager,
Salary=56000.0
Employee Info #
First Name=Micheal,
Last Name=John,
Phone Number=9881245678,
Address=105,Church Street,
Id=3456,
Title=Supervisor,
Salary=56000.0
Employee Info #
First Name=Sachin,
Last Name=Tendulkar,
Phone Number=9456781234,
Address=303,Lake Road,
Id=6789,
Title=Manager,
Salary=67000.0
Employee Info #
First Name=Ricky,
Last Name=Pointing,
Phone Number=9887761234,
Address=505,Park Street,
Id=5690,
Title=Manager,
Salary=90000.0
Employee Info #
First Name=Pat,
Last Name=Simkox,
Phone Number=9123456783,
Address=405,James Street,
Id=5423,
Title=Supervisor,
Salary=78000.0
Employee Info #
First Name=Williams,
Last Name=Kane,
Phone Number=9876543218,
Address=101,Park Street,
Id=1234,
Title=Manager,
Salary=89000.0
Employee Info #
First Name=Micheal,
Last Name=John,
Phone Number=9881245678,
Address=105,Church Street,
Id=3456,
Title=Supervisor,
Salary=56000.0
Employee Info #
First Name=Sachin,
Last Name=Tendulkar,
Phone Number=9456781234,
Address=303,Lake Road,
Id=6789,
Title=Manager,
Salary=67000.0
Employee Info #
First Name=Ricky,
Last Name=Hayes,
Phone Number=9665544332,
Address=505,Park Street,
Id=5690,
Title=Manager,
Salary=97000.0
Employee Info #
First Name=Pat,
Last Name=Simkox,
Phone Number=9123456783,
Address=405,James Street,
Id=5423,
Title=Supervisor,
Salary=78000.0

____________Thank You