Question Find Grocerybilljava Itemjava Employeejava Please Also Create Main Program Test C Q43807500
Below the question, you will find the GroceryBill.java,Item.java, and Employee.java.
Please also create a Main Program to test thecode.
Question:
Suppose a class GroceryBill keeps track of a list of items beingpurchased at a market:
public GroceryBill(Employee clerk)Constructs a grocery bill object for the given clerkpublic void add(Item i)Adds the given item to this billpublic double getTotal()Returns the total cost of these itemspublic void printReceipt()Prints a list of items
Grocery bills interact with Item objects, each of which has thepublic methods that follow. A candy bar item might cost 1.35 with adiscount of 0.25 for preferred customers, meaning that preferredcustomers get it for 1.10. (Some items will have no discount, 0.0.)Currently the preceding classes do not consider discounts. Everyitem in a bill is charged full price, and item discounts areignored.
public double getPrice()Returns the price for this itempublic double getDiscount()Returns the discount for this item
Define a class DiscountBill that extends GroceryBill to computediscounts for preferred customers. Its constructor accepts aparameter for whether the customer should get the discount. Yourclass should also adjust the total reported for preferredcustomers. For example, if the total would have been $80 but apreferred customer is getting $20 in discounts, then getTotalshould report the total as $60 for that customer. Also keep trackof the number of items on which a customer is getting a nonzerodiscount and the sum of these discounts, both as a total amount andas a percentage of the original bill. Include the extra methodsthat follow, which allow a client to ask about the discount. Return0.0 if the customer is not a preferred customer or if no items werediscounted.
public DiscountBill(Employee clerk, boolean preferred)Constructs bill for given clerkpublic int getDiscountCount()Returns the number of items that were discounted, if anypublic double getDiscountAmount()Returns the total discount for this list of items, if anypublic double getDiscountPercent()Returns the percent of the total discount as a percent of whatthe total would have been otherwise
*****************
CLASSES:
*****************
public class Item {
private String name;
private double price;
private double discount;
public Item(String name, double price, double discount) { //Constructor
this.name = name;
this.price = price;
this.discount = discount;
}
// Accessor methods
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public double getDiscount() {
return discount;
}
public String toString() { // toString method for printing thereceipt
return name + “: $” + price + “(-$” + discount + “)”;
}
}
***************************************************************
public class Employee {
String name;
public Employee(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
*******************************************************
public class GroceryBill {
private double total_price;
private int item_count;
private Item receipt[];
private Employee clerk;
public GroceryBill(Employee clerk) { // Constructor withEmployee parameter
total_price = 0;
item_count = 0;
receipt = new Item[25];
this.clerk = clerk;
}
public void add(Item i) { // Mutator method for adding anitem
total_price += i.getPrice();
receipt[item_count] = i;
item_count += 1;
}
// Accessor methods
public double getTotal() {
return total_price;
}
public int getItemCount() {
return item_count;
}
public String getCashierName() {
return clerk.getName();
}
public void printReceipt() { // Printing the bill
System.out.println(receiptToString());
System.out.println(“Cashier Name: ” + clerk.getName());
System.out.println(“Total: $” + this.getTotal());
}
public String receiptToString() {
String receiptText =”Items:n”;
for(int i = 0; i < item_count;i++) {
receiptText +=receipt[i];
receiptText +=”n”;
}
return receiptText;
}
}
Expert Answer
Answer to Below the question, you will find the GroceryBill.java, Item.java, and Employee.java. Please also create a Main Program …
OR