Question

In: Computer Science

you will find a class called Employee. This class should include a constructor that sets name...

you will find a class called Employee. This class should include a constructor that sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will create a new class called Manager that inherits from the class Employee. Add a field named department of type String. Supply a method toString that prints the manager's name, department, and salary. Remember, you may not change anything in the Employee class. You will then create a test class that uses the Manager class. The test class should prompt the user to enter the name, department, and salary. This information should be stored in an array. Upon entry of 3 employee records, the program should output the information you entered. Your program should be able to handle a maximum of 3 entries. You may write the program as a console application or using dialog boxes. Please remember to include the needed comments at the top of your .java file which will identify this assignment. Please refer to Project Format and Grading Policy on the Syllabus regarding programming project expectations for the semester.

Solutions

Expert Solution

Screenshot

Program

Employee.java

/**
* Create a class Employee
* With attributes of name and salary
* Appropriate constructors,getters and setters to manage employee attributes
* Use toString override to formatted attributes display
* @author deept
*
*/
public class Employee {
   //Attributes
   private String name;
   private double salary;
   //Default constructor set name as blank and salary as 0.00
   public Employee() {
       name="";
       salary=0.00;
   }
   //Parameterized constructor set name as passed name and salary as passed value
   public Employee(String name,double salary) {
       this.name=name;
       if(salary<0) {
           this.salary=0.00;
       }
       else {
           this.salary=salary;
       }
   }
   //Getters or accessors
   public String getName() {
       return name;
   }
   public double getSalary() {
       return salary;
   }
   //Setters or mutators
   public void setName(String name) {
       this.name = name;
   }
   public void setSalary(double salary) {
       if(salary<0) {
           this.salary=0.00;
       }
       else {
           this.salary=salary;
       }
   }
   //Override toString() for formatted display
   public String toString() {
       return "Employee name: "+name+", Salary: $"+String.format("%.2f",salary);
   }
}

Manager.java

/**
* Class Manager
* Inherit from Employee
* With additional attribute department
* Appropriate constructors,getters and setters to manage manger attribute
* Use toString override to formatted attributes display
* @author deept
*
*/
public class Manager extends Employee{
   //Attribute
   private String department;
   //Default constructor,set department as blank
   public Manager() {
       super();
       department="";
   }
   //Parameterized constructor,set department as blank
   public Manager(String name,double salary,String department) {
       super(name,salary);
       this.department=department;
   }
   //Getter
   public String getDepartment() {
       return department;
   }
   //Setter
   public void setDepartment(String department) {
       this.department = department;
   }
   //Override toString() for formatted display
   public String toString() {
       return super.toString()+", Department: "+department;
   }
}

Test.java

import java.util.Scanner;
/**
* Create a test class
* Create manage object array of maximum 3 Managers
* Display all Manger details
* @author deept
*
*/
public class Test {
   public static void main(String[] args) {
       //Scanner object
       Scanner sc=new Scanner(System.in);
       //Create 3 Manager object array
       Manager managers[]=new Manager[3];
       //Prompt to enter manager details
       for(int i=0;i<3;i++) {
           System.out.println("Enter Manager"+(i+1)+" details:-");
           System.out.print("Enter name: ");
           String name=sc.nextLine();
           System.out.print("Enter department: ");
           String department=sc.nextLine();
           System.out.print("Enter salary: ");
           double salary=sc.nextDouble();
           //Set Manger into array
           managers[i]=new Manager(name,salary,department);
           sc.nextLine();
           System.out.println();
       }
       //Display manager's details
       System.out.println("\nDisplay Manager details:-");
       for(int i=0;i<3;i++) {
           System.out.println(managers[i]);
       }
   }
}

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

Output

Enter Manager1 details:-
Enter name: Micheal
Enter department: Finanace
Enter salary: 20000

Enter Manager2 details:-
Enter name: Adorn
Enter department: IT
Enter salary: 22000

Enter Manager3 details:-
Enter name: Mark
Enter department: Marketting
Enter salary: 18000


Display Manager details:-
Employee name: Micheal, Salary: $20000.00, Department: Finanace
Employee name: Adorn, Salary: $22000.00, Department: IT
Employee name: Mark, Salary: $18000.00, Department: Marketting


Related Solutions

In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...
Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class.   HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...
Q3) Design a class for saving data of employee, the class should have multiple constructors (constructor...
Q3) Design a class for saving data of employee, the class should have multiple constructors (constructor overloading) for initializing objects with different parameters. The employee class should have different functions for saving and updating bio-data, educational background, and current status like experience, Salary, position & travel history. The employee class should have a function which asks user what do he likes to see about employee (.i.e., Bio-data, current status....) and only show the respective data. Create two objects of interns...
1. From the constructor, you infer that the name of the class containing the constructor must be_______ .
1. From the constructor, you infer that the name of the class containing the constructor must be_______ .2. Fill in the blanks so that the statement will instantiate a JButton object and assigns it to variable of JButton type:JButton btn= _______ ("OK");3. Fill in the blanks to complete the description of the constructor in the corresponding UML class diagram:+<>______( _____ : ______)
JAVA The class will have a constructor BMI(String name, double height, double weight). The class should...
JAVA The class will have a constructor BMI(String name, double height, double weight). The class should have a public instance method, getBMI() that returns a double reflecting the person's BMI (Body Mass Index = weight (kg) / height2 (m2) ). The class should have a public toString() method that returns a String like Fred is 1.9m tall and is 87.0Kg and has a BMI of 24.099722991689752Kg/m^2 (just print the doubles without special formatting). Implement this class (if you wish you...
Define the exception class called TornadoException. The class should have two constructors including one default constructor....
Define the exception class called TornadoException. The class should have two constructors including one default constructor. If the exception is thrown with the default constructor, the method getMessage should return "Tornado: Take cover immediately!" The other constructor has a single parameter, m, of int type. If the exception is thrown with this constructor, the getMessage should return "Tornado: m miles away; and approaching!" Write a Java program to test the class TornadoException.
Part I: The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class.
  Part I:   The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class. * Update the function display() to be a virtual function     * Add function, double weeklyEarning() to be a pure virtual function. This will make Employee an abstract class, so your main will not be able to create any Employee objects. Part II: The Derived Classes Add an weeklyEarning() function to each...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT