In: Computer Science
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 write a code using java. Make sure the code is correct for java eclipse.
Code
Employee class
public class Employee {
private String name;
private double salary;
/**
* @param name
* @param salary
*/
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
/**
* default constuctor
*/
public Employee() {
name="";
salary=0.0;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the salary
*/
public double getSalary() {
return salary;
}
/**
* @param salary the salary to set
*/
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public String toString() {
return "Name: " + name + "\bSalary:
" +String.format("$%,.2f", salary);
}
}
Manager class
public class Manager extends Employee
{
private String department;
/**
* @param name
* @param salary
* @param department
*/
public Manager(String name, double salary, String
department) {
super(name, salary);
this.department = department;
}
/**
* @param name
* @param salary
*/
public Manager() {
super();
department="";
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Name:
"+super.getName()+"\nDepartment: "+department+"\nSalary:
"+String.format("$%,.2f", super.getSalary());
}
}
TestManager class
import java.util.Scanner;
public class TestManager {
public static void main(String[] args) {
Manager managers[]=new
Manager[3];
Scanner scnr=new
Scanner(System.in);
String name,dept;
String sal;
for(int
i=0;i<managers.length;i++)
{
System.out.print("\nEnter name of manager: ");
name=scnr.nextLine();
System.out.print("Enter manager's department: ");
dept=scnr.nextLine();
System.out.print("Enter manager's salary: ");
sal=scnr.nextLine();
managers[i]=new
Manager(name,Double.parseDouble(sal),dept);
}
System.out.println("\nAll managers:
");
for(int
i=0;i<managers.length;i++)
{
System.out.println(managers[i]+"\n");
}
}
}
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.