In: Computer Science
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 hourlyRate * 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.
Remember to submit your pseudocode algorithm
package Array;
import java.util.ArrayList;
// Defines a class to store client information
class Client
{
// Instance variable to store client information
String companyName;
String companyId;
String billingAddress;
String billingCity;
String billingState;
// Default constructor to assign default values
// to instance variable
Client()
{
companyName = companyId = billingAddress =
billingCity = billingState = "";
}// End of default constructor
// Parameterized constructor to assign parameter values
// to instance variables
Client(String cn, String ci, String ba, String bc, String bs)
{
companyName = cn;
companyId = ci;
billingAddress = ba;
billingCity = bc;
billingState = bs;
}// End of parameterized constructor
// Overloads toString() method to return client information
public String toString()
{
return "\n\n Company Name: " + companyName +
"\n Company ID: " + companyId +
"\n Billing Address: " + billingAddress +
"\n Billing City: " + billingCity +
"\n Billing State: " + billingState;
}// End of method
}// End of class Client
// Defines a derived class HourlyClient extended
// from super Client class
class HourlyClient extends Client
{
// Instance variable to store client information
double hourlyRate;
double hoursBilled;
double billingAmount;
// Default constructor to assign default values to instance variable
HourlyClient()
{
// Calls the super class default constructor
super();
hourlyRate = hoursBilled = 0.0;
}// End of default constructor
// Parameterized constructor to assign parameter values
// to instance variables
HourlyClient(String cn, String ci, String ba,
String bc, String bs, double hr, double hb)
{
// Calls the super class parameterized constructor
super(cn, ci, ba, bc, bs);
hourlyRate = hr;
hoursBilled = hb;
billingAmount = 0.0;
}// End of parameterized constructor
// Method to calculate billing amount
void calculateAmount()
{
billingAmount = hourlyRate * hoursBilled;
}// End of method
// Overloads toString() method to return hourly client information
public String toString()
{
// Calls the super class toString() method
// Concatenates hourly client information
return super.toString() +
"\n Hourly Rate: " + hourlyRate +
"\n Hours Billed: " + hoursBilled +
"\n Billing Amount: " + billingAmount;
}// End of method
}// End of class HourlyClient
// Driver class definition
public class ArrayListClient
{
// main method definition
public static void main(String ss[])
{
// Creates a string array and stores company name
String companyName[] = {"Sujan", "Ambica", "Sanjibani",
"Sagar", "Ambuja"};
// Creates a string array and stores company id
String companyId[] = {"111", "123", "256", "568", "898"};
// Creates a string array and stores billing address
String billingAddress[] = {"BBSR", "BAM", "RGDA",
"RKL", "CTC"};
// Creates a string array and stores billing city
String billingCity [] = {"Berhampur", "Bhubaneswar",
"Rayagada", "Rourkela", "Cuttack"};
// Creates a string array and stores billing state
String billingState [] = {"Orissa", "Bihar", "Westbangal",
"Bihar", "Jammu"};
// Creates a double array and stores hourly rate
double hourlyRate [] = {89.56, 55.23, 78.89, 33.45, 91.2};
// Creates a double array and stores hours billed
double hoursBilled [] ={12, 20, 10, 45, 36};
// Creates an array of object of class HourlyClient
// of size 5
HourlyClient hc[] = new HourlyClient[5];
// Creates an array list to store class HourlyClient object
ArrayList<HourlyClient> hcArray =
new ArrayList<HourlyClient>();
// Loops till number of company
for(int c = 0; c < hc.length; c++)
{
// Creates an object of class HourlyClient using
// parameterized constructor and adds it to
// array list
hcArray.add(new HourlyClient(companyName[c],
companyId[c], billingAddress[c],
billingCity[c], billingState[c],
hourlyRate[c], hoursBilled[c]));
// Calls the method to calculate amount
hcArray.get(c).calculateAmount();
// Displays each object information
System.out.println(hcArray.get(c));
}// End of for loop
}// End of main method
}// End of class
Sample Output:
Company Name: Sujan
Company ID: 111
Billing Address: BBSR
Billing City: Berhampur
Billing State: Orissa
Hourly Rate: 89.56
Hours Billed: 12.0
Billing Amount: 1074.72
Company Name: Ambica
Company ID: 123
Billing Address: BAM
Billing City: Bhubaneswar
Billing State: Bihar
Hourly Rate: 55.23
Hours Billed: 20.0
Billing Amount: 1104.6
Company Name: Sanjibani
Company ID: 256
Billing Address: RGDA
Billing City: Rayagada
Billing State: Westbangal
Hourly Rate: 78.89
Hours Billed: 10.0
Billing Amount: 788.9
Company Name: Sagar
Company ID: 568
Billing Address: RKL
Billing City: Rourkela
Billing State: Bihar
Hourly Rate: 33.45
Hours Billed: 45.0
Billing Amount: 1505.2500000000002
Company Name: Ambuja
Company ID: 898
Billing Address: CTC
Billing City: Cuttack
Billing State: Jammu
Hourly Rate: 91.2
Hours Billed: 36.0
Billing Amount: 3283.2000000000003