JAVA u have been hire by the Sandwich queen Company to help organize their emplo
ID: 3769881 • Letter: J
Question
JAVA u have been hire by the Sandwich queen Company to help organize their employees. Create an Employee superclass which contains: - A field forr name - A field for payrate - A constructor that assigns the fields Create a class called SandwichArtisan which extends Employee and contains: - A field for the number of sandwiches made per hour - A field for customers served per hour - Appropriate constructor and accessors Create a class called QueenManager which extends Employee and contains: - A field for the number of employees managed - A field for the paybonus the manager receives - A void method that calculates the paybonus as: paybonus = total customers served per hour * 2 The method must take an array of SandwichArtisans as an argument to calculate the total customers served by all the artisans. Store the result in your class field. - Appropriate constructor and accessors Write a main class which creates 1 QueenManager and 3 SandwichArtisans, making up values for their fields (no need to ask the user). Add the 3 SandwichArtisans to an array and use it to calculate the paybonus of the Manager. Output the name and paybonus earned by the manager, and the name of the employee who served the most customers as the employee of the month
Explanation / Answer
Complete Program:
// File: Employee.java
public class Employee
{
private String name;
private double payrate;
public Employee(String aName, double aPayrate)
{
name = aName;
payrate = aPayrate;
}
public String getName()
{
return name;
}
public double getPayrate()
{
return payrate;
}
}
// File: SandwichArtisan.java
public class SandwichArtisan extends Employee
{
private int sandwiches;
private int customers;
public SandwichArtisan(String aName, double aPayrate, int aSandwiches, int aCustomers)
{
super(aName, aPayrate);
sandwiches = aSandwiches;
customers = aCustomers;
}
public int getSandwiches()
{
return sandwiches;
}
public int getCustomers()
{
return customers;
}
}
// File: QueenManager.java
public class QueenManager extends Employee
{
private int employees;
private double paybonus;
public QueenManager(String aName, double aPayrate, int aEmployees)
{
super(aName, aPayrate);
employees = aEmployees;
paybonus = 0;
}
public void calculatePaybonus(SandwichArtisan[] sa)
{
int totalCustomers = 0;
for(int i = 0; i < sa.length; i++)
totalCustomers += sa[i].getCustomers();
paybonus = totalCustomers * 2;
}
public int getEmployees()
{
return employees;
}
public double getPaybonus()
{
return paybonus;
}
}
// File: SandwichDriver.java
public class SandwichDriver
{
public static void main(String[] args)
{
QueenManager qm = new QueenManager("QueenManager", 120, 50);
SandwichArtisan sa1 = new SandwichArtisan("SandwichArtisan1", 100, 100, 60);
SandwichArtisan sa2 = new SandwichArtisan("SandwichArtisan2", 90, 120, 70);
SandwichArtisan sa3 = new SandwichArtisan("SandwichArtisan3", 110, 90, 65);
SandwichArtisan[] sa = {sa1, sa2, sa3};
qm.calculatePaybonus(sa);
System.out.println("Name earned by the manager: " + qm.getName());
System.out.println("Paybonus earned by the manager: " + qm.getPaybonus());
System.out.println("Name of the employee who served the most customers: " + getEmployeeName(sa));
}
public static String getEmployeeName(SandwichArtisan[] sa)
{
int most = sa[0].getCustomers();
String mostName = "";
for(int i = 1; i < sa.length; i++)
{
if(sa[i].getCustomers() > most)
{
most = sa[i].getCustomers();
mostName = sa[i].getName();
}
}
return mostName;
}
}
Sample Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.