Hello I need help with an assignment. There\'s two parts to this assignment. I n
ID: 3640824 • Letter: H
Question
Hello I need help with an assignment. There's two parts to this assignment.
I need a java code for:
1st part of ASSIGNMENT:
Define a class Employee with the following properties. Every Employee has a name and a salary. The constructor creates an Employee with a name and an initial salary. The method salary_change(amount) will increase or decrease the salary by the specified amount. The method quit() will set the salary of the Employee to zero. The method get_info() will return the current salary of the Employee. Write a program that lets a user create Employee objects and adjust their salaries (by raises or pay cuts). After each user command, the program must print the current salary of the Employee.
Note: A simple interface is sufficient to get user input, nothing fancy is required.
2nd Part of the ASSIGNMENT:
Create a Faculty subclass of Employee which has the additional data of rank and expertise. Rank could be one of Assistant Professor, Associate Professor, or Professor. Expertise would be a String such as ‘Computer Science’, ‘Music’, ‘History’ etc. Create a Staff subclass of Employee which has the additional data of Category (Full or Part time). Provide suitable constructors for your classes. Each of these sub classes must have a change_status() method that changes the rank or category respectively. For example, an Associate Professor could be promoted to Professor; a Full time classified could be demoted to part time. Add a change_status() method to the Employee base class that simply outputs a message “Cannot change this Employee’s status”.
Demonstrate dynamic binding in your main program. Declare an array of Employees (compile time type) but assign different subclasses to each array element (run time type). Show that get_info() and change_status() uses the methods determined by their run time types and displays all the relevant data.
Explanation / Answer
This is the modified 1st part...
import java.util.Scanner;
class Employee
{
private String name;
private double salary;
Employee(String n,double s)
{
name=n;
salary=s;
}
public void salary_change(double amount)
{
salary=salary+amount;
}
void quit()
{
salary=0.0;
}
double get_info()
{
return salary;
}
}
//======================================================
public class EmployeeTest
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
Scanner t=new Scanner(System.in);
System.out.println("Enter the number of employees: ");
int a=s.nextInt();
int i;
String n;
double sal;
Employee []ob=new Employee[a];
for(i=0;i<a;i++)
{
System.out.println("Enter the name of employee #"+(i+1)+": ");
n=t.nextLine();
System.out.println("Enter the initial salary of employee #"+(i+1)+": ");
sal=s.nextDouble();
ob[i]=new Employee(n,sal);
System.out.println("Enter the new salary amount of employee #"+(i+1)+": ");
sal=s.nextDouble();
ob[i].salary_change(sal);
}
for(i=0;i<a;i++)
{
System.out.println("Salary of Employee #"+(i+1)+": ");
System.out.println("====================================");
System.out.println("salary: "+ob[i].get_info());
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.