Question: JAVA Create a class called Lab5 to test your classes. Create an ArrayList to hold Taxable objects and add two Cars and two Employees to

JAVA

Create a class called Lab5 to test your classes. Create an ArrayList to hold Taxable objects and add two Cars and two Employees to this list. Iterate through the ArrayList calling printTax() on each of the objects. Classes are as below:

Taxable.java

public interface Taxable { public abstract double calculateTax();

public abstract void printTax(); }

PRSI.java

public interface PRSI { static final double rate = 0.04; // 4%

public abstract double calculatePRSI(); }

Car.java

public class Car implements Taxable {

private String make, model;

private int size;

private int tax;

public Car(String make, String model, int size) {

this.make = make;

this.model = model;

this.size = size;

}

@Override

public double calculateTax() {

// TODO Auto-generated method stub

if (size < 1000)

tax = 200;

else if (tax < 2000)

tax = 900;

else

tax = 1800; return tax;

}

public void printTax() {

System.out.println("Car make is " + make + ", model is " + model + ", engine size is " + size + ". The tax for this model is " + tax + "");

}

}

Employee.java

public class Employee implements PRSI, Taxable {

private String name;

private int PPS;

private double salary, tax;

private double rate = 0.04; double PRSI;

public Employee(String name, double salary, int PPS) {

this.name = name;

this.salary = salary;

this.PPS = PPS;

}

@Override

public double calculateTax() {

// TODO Auto-generated method stub

if (salary < 33800) {

tax = 0.2 * salary;

} else {

tax = 0.2 * 33800 + 0.4 * (salary - 33800);

} return tax;

}

public void printTax() {

System.out.println("Employee name is " + name + ", PPS of employee is " + PPS + ", salary of employee is " + salary + " " + ", PRSI for this employee is " + PRSI + " and tax is " + tax);

}

@Override

public double calculatePRSI() {

// TODO Auto-generated method stub

double weekSalary = salary / 52;

if (weekSalary < 352)

PRSI = 0;

else

PRSI = (weekSalary * rate) * 52; return PRSI;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!