In: Computer Science
Please provide step by step detailing on how i should do this assignment. 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 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 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. Also, please provide explanation on how to create each class on java eclipse so that the code can run successfully. Please provide description for everything, I’m a beginner trying to do this assignment.
- Please rename classes as per the requirement.
- In eclipse, goto > File > New > Java Project.
- Give a project name and create Project
- In the project, right click and create a package of your
choice.
- In the package, create these classes and then run the class with
the main method.
- Its your wish to make seperate files are a single file having all
the classes.
Kindly upvote if
this helped. Comment for more help
Code:
import java.util.Scanner;
public class TestingManager {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // used to take user input
double salary;
String name,dept;
Manager m[] = new Manager[3]; // initializes for 3 records
for(int i=1;i<=3;i++) {
System.out.println("Enter Record for employee number "+i);
System.out.println("Enter name");
name = sc.nextLine();
System.out.println("Enter salary");
salary = Double.parseDouble(sc.nextLine());
System.out.println("Enter department");
dept = sc.nextLine();
m[i-1] = new Manager(); // creating object
m[i-1].setDepartment(dept); // setting data to each object record
m[i-1].setName(name);
m[i-1].setSalary(salary);
}
sc.close();
System.out.println("Information of employees\n");
for(int i=1;i<=3;i++) {
System.out.println("Record for employee number "+i);
System.out.println("Name is "+m[i-1].getName());
System.out.println("Salary is "+m[i-1].getSalary());
System.out.println("Department is "+m[i-1].getDepartment()+"\n");
}
}
}
class Emp{
String name; //these are two class variables
public String getName() { // get name method
return name;
}
public void setName(String name) { // set name method
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
double salary;
Emp(){ // when object of class is created, constructor is invoked first
name = "";
salary = 0.00;
}
public String toString() {
return "Salary of "+name+" is "+salary; // it will return as "salary of aman is 1111.11";
}
}
class Manager extends Emp{
String department;
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String toString() {
return "Salary of "+name+" is "+salary+" having department "+department; // as we have inherited, public class variables are accessible in child class directly
}
}
Sample Output
Snapshot for indent