Question

In: Computer Science

Using JAVA Create a class Client. Your Client class should include the following attributes: Company Name...

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.

Solutions

Expert Solution

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


Related Solutions

using java Create a class Rectangle with attributes length and width both are of type double....
using java Create a class Rectangle with attributes length and width both are of type double. In your class you should provide the following: Provide a constructor that defaults length and width to 1. Provide member functions that calculate the area, perimeter and diagonal of the rectangle. Provide set and get functions for the length and width attributes. The set functions should verify that the length and width are larger than 0.0 and less that 50.0. Provide a member function...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
Create a Class to contain a customer order Create attributes of that class to store Company...
Create a Class to contain a customer order Create attributes of that class to store Company Name, Address and Sales Tax. Create a public property for each of these attributes. Create a class constructor without parameters that initializes the attributes to default values. Create a class constructor with parameters that initializes the attributes to the passed in parameter values. Create a behavior of that class to generate a welcome message that includes the company name. Create a Class to contain...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
Java: Create a class and name it MyArray and implement following method. * NOTE: if you...
Java: Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items in the...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
using Java Implement a class called Binomial_Coefficient o Your class has 2 int attributes, namely K...
using Java Implement a class called Binomial_Coefficient o Your class has 2 int attributes, namely K and n o Create an overloaded constructor to initialize the variables into any positive integers such that n > k > 0o Create a method that calculates the value of binomial coefficient, C(n,k) , using the following rule: ▪ For an array of size (n+1) X (k+1) ▪ Array [n][k] = Array[n-1][ k-1]+ Array[n-1] [k]▪ Array[n][0]= Array[n][n] = 1 ▪ Hence, C(n,k) = array...
In simple Java language algorithm: Implement a static stack class of char. Your class should include...
In simple Java language algorithm: Implement a static stack class of char. Your class should include two constructors. One (no parameters) sets the size of the stack to 10. The other constructor accepts a single parameter specifying the desired size of the stack a push and pop operator an isEmpty and isFull method . Both return Booleans indicating the status of the stack Using the stack class you created in problem 1), write a static method called parse that parses...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after a Cat. You should have instance variables as follows: The Cat’s name The number of mice caught by the Cat. Whether or not the Cat is secretly plotting to kill you Note that you will need to choose both good types and meaningful identifiers for each of these instance variables. You may also assume that the Cat is not automatically always secretly plotting to...
Please use java to answer the below question. (i) Create a class Pencil with the attributes...
Please use java to answer the below question. (i) Create a class Pencil with the attributes brand (which is a string) and length (an integer) which are used to store the brand and length of the ruler respectively. Write a constructor Pencil (String brand, int length) which assigns the brand and length appropriately. Write also the getter/setter methods of the two attributes. Save the content under an appropriate file name. Copy the content of the file as the answers. (ii)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT