You are on page 1of 11

1.

Employee and ProductionWorker Classes


Design a class named Employee. The class should keep the following information in fields:
• Employee name
• Employee number in the format XXX–L, where each X is a digit within the range 0–9
and the L is a letter within the range A–M.
• Hire date
Write one or more constructors and the appropriate accessor and mutator methods for the
class. Next, write a class named ProductionWorker that extends the Employee class.
The ProductionWorker class should have fields to hold the following information:
• Shift (an integer)
• Hourly pay rate (a double)
The workday is divided into two shifts: day and night. The shift field will be an integer value
representing the shift that the employee works. The day shift is shift 1 and the night shift is shift
2. Write one or more constructors and the appropriate accessor and mutator methods for the
class. Demonstrate the classes by writing a program that uses a ProductionWorker object.
2. ShiftSupervisor Class
In a particular factory, a shift supervisor is a salaried employee who supervises a shift. In
addition to a salary, the shift supervisor earns a yearly bonus when his or her shift meets
production goals. Design a ShiftSupervisor class that extends the Employee class you
created in Problem #1. The ShiftSupervisor class should have a field that holds the annual
salary and a field that holds the annual production bonus that a shift supervisor has earned. Write
one or more constructors and the appropriate accessor and mutator methods for the class.
Demonstrate the class by writing a program that uses a ShiftSupervisor object.
3. Person and Customer Classes
Design a class named Person with fields for holding a person’s name, address, and telephone
number. Write one or more constructors and the appropriate mutator and accessor methods for
the class’s fields.
Next, design a class named Customer, which extends the Person class. The Customer class
should have a field for a customer number and a boolean field indicating whether the customer
wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and
accessor methods for the class’s fields. Demonstrate an object of the Customer class in a simple
program.
4. PreferredCustomer Class
A retail store has a preferred customer plan where customers can earn discounts on all their
purchases. The amount of a customer’s discount is determined by the amount of the customer’s
cumulative purchases in the store as follows:
• When a preferred customer spends $500, he or she gets a 5 percent discount on all
future purchases.
• When a preferred customer spends $1,000, he or she gets a 6 percent discount on all
future purchases.
• When a preferred customer spends $1,500, he or she gets a 7 percent discount on all
future purchases.
• When a preferred customer spends $2,000 or more, he or she gets a 10 percent discount
on all future purchases.
Design a class named PreferredCustomer, which extends the Customer class you created
in Problem #3. The PreferredCustomer class should have fields for the amount of the
customer’s purchases and the customer’s discount level. Write one or more constructors and the
appropriate mutator and accessor methods for the class’s fields. Demonstrate the class in a
simple program.
Answers:

1. Employee and ProductionWorker Classes


public class Main {

public static void main(String[] args) {

ProductionWorker PW = new ProductionWorker("Elsa", "235-C",


"12-10-2020", 1, 550.00);

System.out.println("\n Employee Name: " + PW.getEmployeeName() +


"\n Employee Number: " + PW.getEmployeeNumber()
+ "\n Hired Date: " + PW.getHireDate() + "\n Shift: " +
PW.getShift() +
"\n Hourly Pay Rate: " + PW.getHourlyPayRate());
}
}

public class Employee {

String EmployeeName, EmployeeNumber, HireDate;

public Employee(String Ename, String Enum, String HD){


this.EmployeeName = Ename;
this.EmployeeNumber = Enum;
this.HireDate = HD;
}
public String getEmployeeName() {
return EmployeeName;
}
public void setEmployeeName(String employeeName) {
EmployeeName = employeeName;
}
public String getEmployeeNumber() {
return EmployeeNumber;
}
public void setEmployeeNumber(String employeeNumber) {
EmployeeNumber = employeeNumber;
}
public String getHireDate() {
return HireDate;
}
public void setHireDate(String hireDate) {
HireDate = hireDate;
}
}
public class ProductionWorker extends Employee{

private int shift;


private double HourlyPayRate;

ProductionWorker(String EmployeeName, String EmployeeNum, String


HiredDate,
int shift, double HourlyPayRate){
super(EmployeeName, EmployeeNum, HiredDate);
this.shift = shift;
this.HourlyPayRate = HourlyPayRate;
}
public int getShift() { return shift; }
public void setShift(int shift) { this.shift = shift; }
public double getHourlyPayRate() { return HourlyPayRate; }
public void setHourlyPayRate(double hourlyPayRate) { HourlyPayRate =
hourlyPayRate; }
}

OutPut:
2. ShiftSupervisor Class
public class Main {

public static void main(String[] args) {

ShiftSupervisor SS = new ShiftSupervisor("Elsa", "235-C",


"12-10-2020", 80000, 5000);

System.out.println("\n Employee Name: " + SS.getEmployeeName() +


"\n Employee Number: " +
SS.getEmployeeNumber() + "\n Hired Date: " +
SS.getHireDate() + "\n Annual Salary: "
+ SS.getAnnualSalary() + "\n Production Bonus: " +
SS.getProductionBonus());
}
}

public class Employee {

String EmployeeName, EmployeeNumber, HireDate;

public Employee(String Ename, String Enum, String HD){


this.EmployeeName = Ename;
this.EmployeeNumber = Enum;
this.HireDate = HD;
}
public String getEmployeeName() {
return EmployeeName;
}
public void setEmployeeName(String employeeName) {
EmployeeName = employeeName;
}
public String getEmployeeNumber() {
return EmployeeNumber;
}
public void setEmployeeNumber(String employeeNumber) {
EmployeeNumber = employeeNumber;
}
public String getHireDate() {
return HireDate;
}
public void setHireDate(String hireDate) {
HireDate = hireDate;
}
}
public class ShiftSupervisor extends Employee{

private double AnnualSalary, ProductionBonus;

public ShiftSupervisor(String Ename, String Enum, String HD, double


AnnualSalary, double ProductionBonus) {
super(Ename, Enum, HD);
this.AnnualSalary = AnnualSalary;
this.ProductionBonus = ProductionBonus;
}
public double getAnnualSalary() { return AnnualSalary; }
public void setAnnualSalary(double annualSalary) { AnnualSalary =
annualSalary; }
public double getProductionBonus() { return ProductionBonus; }
public void setProductionBonus(double productionBonus) {
ProductionBonus = productionBonus; }
}

OutPut:
3. Person and Customer Classes
public class Main {

public static void main(String[] args) {

Customer c = new Customer("Jay", "General Santos City",


"123-45-678",21, true );

System.out.println("\n Customer Name: " + c.getPersonName() + "\n


Address: " + c.getAddress()
+ "\n Telephone Number: " + c.getTelephoneNumber() + "\n Customer
no. " + c.getCustomerNumber()
+ "\n Want to be add on the mailing list? " + c.isDecision());
}
}

public class Person {


String PersonName, Address, TelephoneNumber;
public Person(String PName, String PAdd, String PTel) {
this.PersonName = PName;
this.Address = PAdd;
this.TelephoneNumber = PTel;
}
public String getPersonName() { return PersonName; }
public void setPersonName(String personName) { PersonName =
personName; }
public String getAddress() { return Address; }
public void setAddress(String address) { Address = address; }
public String getTelephoneNumber() { return TelephoneNumber; }
public void setTelephoneNumber(String telephoneNumber) {
TelephoneNumber = telephoneNumber; }
}

public class Customer extends Person{


private int CustomerNumber;
private boolean decision;
public Customer(String PName, String PAdd, String PTel, int CNumber,
boolean Cdecision) {
super(PName, PAdd, PTel);
this.CustomerNumber = CNumber;
this.decision = Cdecision;
}
public int getCustomerNumber() { return CustomerNumber; }
public void setCustomerNumber(int customerNumber) { CustomerNumber =
customerNumber; }
public boolean isDecision() { return decision; }
public void setDecision(boolean decision) { this.decision = decision;
}
}
OutPut:
4. PreferredCustomer Class
public class Main {

public static void main(String[] args) {

PrefferedCustomer PC = new PrefferedCustomer("Jay", "General


Santos City",
"123-45-678",21, true , 2500.00);
System.out.println("\n Customer Name: " + PC.getPersonName() + "\n
Address: " + PC.getAddress()
+ "\n Telephone Number: " + PC.getTelephoneNumber() + "\n Customer
no. " + PC.getCustomerNumber()
+ "\n Want to be add on the mailing list? " + PC.isDecision()
+ "\n\n Preferred Customer" + "\n Total Purchase: " +
PC.getCustumerSpends() +
"\n Customer's Discount: " + PC.getCustomerDiscount());
}
}

public class Person {


String PersonName, Address, TelephoneNumber;
public Person(String PName, String PAdd, String PTel) {
this.PersonName = PName;
this.Address = PAdd;
this.TelephoneNumber = PTel;
}
public String getPersonName() { return PersonName; }
public void setPersonName(String personName) { PersonName =
personName; }
public String getAddress() { return Address; }
public void setAddress(String address) { Address = address; }
public String getTelephoneNumber() { return TelephoneNumber; }
public void setTelephoneNumber(String telephoneNumber) {
TelephoneNumber = telephoneNumber; }
}

public class Customer extends Person{


private int CustomerNumber;
private boolean decision;
public Customer(String PName, String PAdd, String PTel, int CNumber,
boolean Cdecision) {
super(PName, PAdd, PTel);
this.CustomerNumber = CNumber;
this.decision = Cdecision;
}
public int getCustomerNumber() { return CustomerNumber; }
public void setCustomerNumber(int customerNumber) { CustomerNumber =
customerNumber; }
public boolean isDecision() { return decision; }
public void setDecision(boolean decision) { this.decision = decision;
}
}
public class PrefferedCustomer extends Customer{

private double CustumerSpends;


String CustomerDiscount;

public PrefferedCustomer(String PName, String PAdd, String PTel, int


CNumber,
boolean Cdecision, double CustomerSpends) {
super(PName, PAdd, PTel, CNumber, Cdecision);
this.CustumerSpends = CustomerSpends;
if(CustumerSpends >= 500 && CustumerSpends <= 999){
CustomerDiscount = "5%";
}
if(CustumerSpends >= 1000 && CustumerSpends <= 1499){
CustomerDiscount = "6%";
}
if(CustumerSpends >= 1500 && CustumerSpends <= 1999){
CustomerDiscount = "7%";
}
if(CustumerSpends >= 2000){
CustomerDiscount = "10%";
}
this.CustomerDiscount = CustomerDiscount;
}

public double getCustumerSpends() {


return CustumerSpends;
}

public void setCustumerSpends(double custumerSpends) {


CustumerSpends = custumerSpends;
}

public String getCustomerDiscount() {


return CustomerDiscount;
}

public void setCustomerDiscount(String customerDiscount) {


if(CustumerSpends >= 500 && CustumerSpends <= 999){
CustomerDiscount = "5%";
}
if(CustumerSpends >= 1000 && CustumerSpends <= 1499){
CustomerDiscount = "6%";
}
if(CustumerSpends >= 1500 && CustumerSpends <= 1999){
CustomerDiscount = "7%";
}
if(CustumerSpends >= 2000){
CustomerDiscount = "10%";
}
CustomerDiscount = customerDiscount;
}
}
OutPut:

You might also like