Question

In: Computer Science

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 new class called Manager that inherits from the class Employee. Add a field named department of type String. Supply a method toStringthat 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 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 answer this by creating a code for a java eclipse. Make sure the code runs smoothly. Also post screen shots of it running

Solutions

Expert Solution

  • 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...
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...
in JAVA PLEASE SHOW OUTPUT! PriorityQueueUserDefinedObjectExample (20) Create an Employee class which implements Comparable<Employee> The constructor...
in JAVA PLEASE SHOW OUTPUT! PriorityQueueUserDefinedObjectExample (20) Create an Employee class which implements Comparable<Employee> The constructor consists of an employee’s first name and an employee’s salary, both of which are instance variables. Create accessor and mutator methods for both of these variables Write an equals method that returns true if the salaries are equal with one cent and the names are exactly equal Write a compareTo method that returns 1 if the salary of this employee is greater than the...
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...
Modify the supplied payroll system to include a private instance variable called joinDate in class Employee...
Modify the supplied payroll system to include a private instance variable called joinDate in class Employee to represent when they joined the company. Use the Joda-Time library class LocalDate as the type for this variable. See http://www.joda.org/joda-time/index.html for details end examples of how to use this library. You may also have to download the Joda-Time library (JAR File) and include this in your CLASSPATH or IDE Project Libraries. Use a static variable in the Employee class to help automatically assign...
- Create a java class named SaveFile in which write the following: Constructor: The class's constructor...
- Create a java class named SaveFile in which write the following: Constructor: The class's constructor should take the name of a file as an argument A method save (String line): This method should open the file defined by the constructor, save the string value of line at the end of the file, and then close the file. - In the same package create a new Java class and it DisplayFile in which write the following: Constructor: The class's constructor...
In C++ Write a class named TestScores. The class constructor should accept an array of test...
In C++ Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a member function that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an exception. Demonstrate the class in program.
1. A constructor is a special Class member method. It is automatically called when an object...
1. A constructor is a special Class member method. It is automatically called when an object of the class is created. It can also be called more than once after the object is created. 2. In Java, the new operator is used to create an instance/object of a class in the heap. 3. A reference variable is a memory location contains an address of an object stored in the stack. 4. Encapsulation and abstraction are both the pillars of Object-Oriented...
Create a class called employee which has the following instance variables: Employee ID number Salary Years...
Create a class called employee which has the following instance variables: Employee ID number Salary Years at the company Your class should have the following methods: New employee which reads in an employee’s ID number, salary and years of service Anniversary which will up the years of service by 1 You got a raise which will read in how much the raise was (a percent) and then calculate the new salary You get a bonus which gives a yearly bonus...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT