In: Computer Science
Using JAVA
Create a class Client. Your Client class should include the following attributes:
Company Name (string)
Company id (string)
Billing address (string)
Billing city (string)
Billing state (string)
Write a constructor to initialize the above Employee attributes.
Create another class HourlyClient that inherits from the Client class. HourClient must use the inherited parent class variables and add in hourlyRate and hoursBilled. Your Hourly Client class should contain a constructor that calls the constructor from the Client class to initialize the common instance variables but also initializes the hourlyRate and hoursBilled. Add a billing method to HourlyClient to calculate the amount due from a service provided. Note that billing amount is hourly rate * hoursBilled
Create a test class that prompts the user for the information for five hourly clients, creates an ArrayList of 5 hourly client objects, display the attributes and billing for each of the five hourly clients. Display the company name and billing amount for each company and the total billing amount for all five companies.
If you have any problem with the code feel free to comment.
Program
import java.util.ArrayList;
class Client {
//instance variables
//its protected for inheritance purpose
protected String name, address, city, state;
protected int id;
//parameterized constructor
public Client(String name, String address, String
city, String state, int id) {
this.name = name;
this.address = address;
this.city = city;
this.state = state;
this.id = id;
}
}
class HourlyClient extends Client{
//instance variables
private int hrRate, hrBill;
public HourlyClient(String name, String address,
String city, String state, int id, int hrRate, int hrBill) {
super(name, address, city, state,
id);//calling Client constructor
this.hrRate = hrRate;
this.hrBill = hrBill;
}
public int amountDue() {//calculating billing
amount
return hrRate * hrBill;
}
@Override//shoiwng comapny name and billing
amount
public String toString() {
return "Name: "+name+" Billing
Amount: "+amountDue();
}
}
public class Test {
public static void main(String[] args) {
int total =0;
ArrayList<HourlyClient> ar =
new ArrayList<>();
//dummy data change it
accordingly
ar.add(new HourlyClient("Fast
Food", "3744 Collins Street", "Tampa", "Florida", 1231, 300,
40));
ar.add(new HourlyClient("Classic
Ornaments", "3744 Collins Street", "Tampa", "Florida", 1232, 120,
20));
ar.add(new HourlyClient("Fruits
ltd.", "3744 Collins Street", "Tampa", "Florida", 1233, 150,
40));
ar.add(new HourlyClient("Vegetable
ltd", "3744 Collins Street", "Tampa", "Florida", 1234, 200,
60));
ar.add(new HourlyClient("Meat ltd",
"3744 Collins Street", "Tampa", "Florida", 1235, 400, 50));
System.out.println("--------------List of
Comapnies--------------");
for(HourlyClient i: ar) {
System.out.println(i);
total+=
i.amountDue();//calculating total billing amount
}
System.out.println("Total Billing
Amount: "+total);
}
}
Output