Question

Create a Java application, that support the following: Create an Employee class, which holds following information:...

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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/ The java test program that demonstrates the the Employee class
* the program prompts user to enter the first ,last names, id, salary and title
* as inputs from user for 5 employees and then display the results to console
* output window.
/
//TestEmployee.java
import java.util.Scanner;
public class TestEmployee
{
public static void main(String[] args)
{
String firstName;
String lastName;
int id;
double salary;
String title;
/*Create an array of Employee class of size,5*/
Employee [] emps=new Employee[5];
//create an instance of Scanner class
Scanner scanner=new Scanner(System.in);
/*Read employee details */
for (int i = 0; i < emps.length; i++)
{
System.out.printf("Enter the first name : ");
firstName=scanner.nextLine();
System.out.printf("Enter the last name : ");
lastName=scanner.nextLine();
System.out.printf("Enter the id : ");
id=Integer.parseInt(scanner.nextLine());
System.out.printf("Enter the salary : ");
salary=Double.parseDouble(scanner.nextLine());
System.out.printf("Enter the title : ");
title=scanner.nextLine();
emps[i]=new Employee(firstName, lastName, id, salary, title);
}
System.out.println("Employee object details ");
for (int i = 0; i < emps.length; i++)
{
System.out.println(emps[i].toString());
}

}//end of the main method
}//end of the class

------------------------------------------------------------------------

public class Employee
{
private String firstName;
private String lastName;
private int id;
private double salary;
private String title;

public Employee()
{
this.firstName = "unknown";
this.lastName = "unknown";
this.id = 0;
this.salary = 0;
this.title = "unknown";;
}
public Employee(String firstName, String lastName, int id)
{
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.salary = 0;
this.title = "unknown";;
}
public Employee(String firstName, String lastName, int id, double salary, String title) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.salary = salary;
this.title = title;
}
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 int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}

//Override
public String toString() {
String str="";
str="Name : "+firstName+" "+lastName+
"\nID : "+id+
"\nTitle : "+title+
"\nSalary"+salary;

return str;
}
//Override
public boolean equals(Object obj) {
Employee other=(Employee)obj;
return firstName.equals(other.getFirstName()) &&
lastName.equals(other.getLastName()) &&
title.equals(other.getTitle()) &&
id==other.getId() &&
salary==other.getSalary() ;
}
}

------------------------------------------------------------------------

Sample Output:
Enter the first name : john
Enter the last name : M
Enter the id : 1234
Enter the salary : 25000
Enter the title : Doctor
Enter the first name : Karim
Enter the last name : A
Enter the id : 1235
Enter the salary : 35000
Enter the title : Accountant
Enter the first name : Marsh
Enter the last name : King
Enter the id : 12365
Enter the salary : 45000
Enter the title : Scientist
Enter the first name : jumar
Enter the last name : gul
Enter the id : 123658
Enter the salary : 85000
Enter the title : Director
Enter the first name : Sundar
Enter the last name : Pichiai
Enter the id : 2568
Enter the salary : 960000
Enter the title : CEO
Employee object details
Name : john M
ID : 1234
Title : Doctor
Salary25000.0
Name : Karim A
ID : 1235
Title : Accountant
Salary35000.0
Name : Marsh King
ID : 12365
Title : Scientist
Salary45000.0
Name : jumar gul
ID : 123658
Title : Director
Salary85000.0
Name : Sundar Pichiai
ID : 2568
Title : CEO
Salary960000.0

UML class diagram:

Add a comment
Know the answer?
Add Answer to:
Create a Java application, that support the following: Create an Employee class, which holds following information:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • create a java class named Person that has 3 attributes: name, age and weight. include a...

    create a java class named Person that has 3 attributes: name, age and weight. include a default and parametrize constructor. include all setters and getters needed and a method that is used to display the information about the person

  • JAVA 1336 Problem: Complete Programming Project 1 (pg. 339, Savitch). The defined class will be HotDogStand.java...

    JAVA 1336 Problem: Complete Programming Project 1 (pg. 339, Savitch). The defined class will be HotDogStand.java and will also contain: • A default constructor • An overloaded constructors Getters and Setters A 'copy' constructor, -3 A 'toString' method, An 'equals' method, A finalize' method, Remember to THOROUGHLY test the application in a separate test file, HotDogStandTest.java. Requirements: You will submit the following with this lab (face-to-face sections). Online sections will turn their labs in through Blackboard as usual: a. The...

  • Write code to create a Java class called "Student". The class should hold information about a...

    Write code to create a Java class called "Student". The class should hold information about a student: name, id and whether or not the student is currently registered. There should be a constructor that takes name, id and registration status. Add getters and setters for the three properties. Make sure that you use appropriate visibility modifiers (public vs. private).

  • Write an ADT named circle in java containing the following. Include data: radius (double) Include methods:...

    Write an ADT named circle in java containing the following. Include data: radius (double) Include methods: A no-argument constructor A constructor that sets the data to passed values Getters and setters for each piece of data getArea (Math.PI * radius * radius … try using a Math method here) getDiameter (radius * 2) getCircumference (2 * Math.PI * radius) A toString( ) method to display the object data Include Javadoc comments for the class and every method, and generate the...

  • Java program Candidate Class: This class records the information for each candidate that is running for...

    Java program Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are running for the party they represent total votes a boolean value to record if they won Methods: Custom constructor that accepts first and last name, office and party Custom constructor that accepts an instance of another customer Getters for all instance variables and setters for total votes and the boolean variable toString: This method...

  • Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman...

    Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT