Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This question is already answered on chegg, but I need help to a few other metho

ID: 3555465 • Letter: T

Question

This question is already answered on chegg, but I need help to a few other methods and base it of a provided client file. In building java program ed two, this problem is in Chapter 10 and it's programing project 1. Please help me solve it based on the client code and output...

I'll a lot more ponits if someone tell me how, it wont let me add more. I know this is a big question.

HERE IS AN OUTLINE ON WHAT TO USE

Class: Item
This class stores information about the individual items. It must implement the following public methods:
Method Description
Item(name, price)
Constructor that takes a name and a price as arguments. The name will
be a String and the price will be a double. Should throw an
IllegalArgumentException is price is negative.
Item(name, price,
bulk quantity, bulk
price)
Constructor that takes a name and a single-item price and a bulk quantity
and a bulk price as arguments. The name will be a String and the
quantity will be an int value and the prices will be double values. Should
throw an IllegalArgumentException if any number is negative.
priceFor(quantity)
Returns the price for a given quantity of the item (taking into account bulk
price, if applicable). Quantity will be an int . Should throw an
IllegalArgumentException if quantity is negative.
toString()
Returns a String representation of this item: name followed by a comma
and space followed by price. If this has a bulk price, then you should
append an extra space and a parenthesized description of the bulk
pricing that has the bulk quantity, the word for and the bulk price.
equals(Object) Returns true if both Item objects are equal
Class: Catalog
This class stores information about a collection of Item objects. It should be implemented using an
ArrayList to store the Catalog of Items, and it must implement the following public methods:
Method Description
Catalog(name)
Constructor that takes the name of this catalog as a parameter. The
name will be a String.
add(item) Adds an Item at the end of the ArrayList list.
size() Returns the number of items in the list.
get(index) Returns a reference to the Item with the given index (0-based).
getName() Returns the name of this catalog.
equals(Object) Returns true if both Catalog objects are equal
Class: ItemOrder

This class stores information about a particular Item object and the quantity ordered for that item. It
must implement the following public methods:
Method Description
ItemOrder(item, quantity)
Constructor that creates an item order for the given item and given
quantity. The quantity will be an int value. Should throw an
IllegalArgumentException if the quantity is negative.
getPrice() Returns the cost for this item order.
getItem() Returns a reference to the item in this order.
getQuantity() Returns the quantity of the order Item
equals(Object) Returns true if both ItemOrder objects are equal


Class: ShoppingCart
You should implement a class called ShoppingCart that stores information about the overall order. It
must implement the following public methods:
Method Description
ShoppingCart() Constructor that creates an empty list of item orders.
add(item order)
Adds an item order to the list, replacing any previous order for this item
with the new order. The parameter will be of type ItemOrder.
setDiscount(value)
Sets whether or not this order gets a discount (true: A discount of 10%
applies to the total order, false: No discount applies).
getTotal() Returns the total cost of the shopping cart.
equals(Object) Returns true if both ShoppingCart objects are equal

Here is the client file code.............

public class ShoppingOrderClient
{
public static void main(String[] args)
{
   // Create store items for the CS-211 Gift Catalog
   Item item1 = new Item("silly putty", 3.95, 10, 19.99);
   Item item2 = new Item("silly string", 3.50, 10, 14.95);
   Item item3 = new Item("bottle o bubbles", 0.99);
   Item item4 = new Item("Nintendo Wii system", 389.99);
   Item item5 = new Item("Mario Computer Science Party 2 (Wii)", 49.99);
   Item item6 = new Item("Don Knuth Code Jam Challenge (Wii)", 49.99);
   Item item7 = new Item("Computer Science pen", 3.40);
   Item item8 = new Item("Rubik's cube", 9.10);
   Item item9 = new Item("Computer Science Barbie", 19.99);
   Item item10 = new Item("'Java Rules!' button", 0.99, 10, 5.0);
   Item item11 = new Item("'Java Rules!' bumper sticker", 0.99, 20, 8.95);
  
   // Now create the CS-211 Gift Catalog
Catalog catalogList = new Catalog("CS-211 Gift Catalog");
catalogList.add(item1);
catalogList.add(item2);
catalogList.add(item3);
catalogList.add(item4);
catalogList.add(item5);
catalogList.add(item6);
catalogList.add(item7);
catalogList.add(item8);
catalogList.add(item9);
catalogList.add(item10);
catalogList.add(item11);
  
// Then create some orders to test the various
ItemOrder order1A = new ItemOrder(item1, 10);
ItemOrder order1B = new ItemOrder(item1, 9);
ItemOrder order2 = new ItemOrder(item3, 6);
ItemOrder order3A = new ItemOrder(item5, 1);
ItemOrder order3B = new ItemOrder(item5, 5);
ItemOrder order3C = new ItemOrder(item5, 0);
ItemOrder order4 = new ItemOrder(item7, 3);
ItemOrder order5 = new ItemOrder(item10, 12);
ItemOrder order6A = new ItemOrder(item11, 12);
ItemOrder order6B = new ItemOrder(item11, 20);
ItemOrder order7 = new ItemOrder(item2, 20);
ItemOrder order8 = new ItemOrder(item9, 0);
  
// Next, create carts for five different customers.
ShoppingCart cart1 = new ShoppingCart();
cart1.add(order1A);
cart1.add(order3A);
cart1.add(order5);
cart1.add(order2);
  
ShoppingCart cart2 = new ShoppingCart();
cart2.add(order4);
cart2.add(order6B);
cart2.add(order3B);
cart2.add(order3C);
cart2.add(order2);
  
ShoppingCart cart3 = new ShoppingCart();
cart3.add(order2);
cart3.add(order7);
  
ShoppingCart cart4 = new ShoppingCart();
cart4.add(order8);
  
ShoppingCart cart5 = new ShoppingCart();
cart5.add(order6A);
cart5.add(order3A);
cart5.add(order3B);
cart5.add(order1B);
  
ShoppingCart[] carts = new ShoppingCart[]
                   { cart1, cart2, cart3, cart4, cart5 };
  
  
// Now display the results
// First, display the CS-211 Gift Catalog
System.out.println(catalogList);
  
// Now display each customer's cart
int customerNmbr = 1;
for (ShoppingCart cart : carts)
{
   System.out.println(" Customer # " + customerNmbr++ +
           " Shopping cart: " + cart);
}
  
// Finally, allow a discount for customer #5
cart5.setDiscount(true);
   System.out.println(" Customer #5B Shopping cart: " + cart5);

   } // End method: main(String[])
  
} // End class definition: ShoppingOrderClient

Here is what the output should look like...

Catalog: CS-211 Gift Catalog:
Item 1:
silly putty @ 3.95 (10 for 19.99)
Item 2:
silly string @ 3.50 (10 for 14.95)
Item 3:
bottle o bubbles @ 0.99
Item 4:
Nintendo Wii system @ 389.99
Item 5:
Mario Computer Science Party 2 (Wii) @ 49.99
Item 6:
Don Knuth Code Jam Challenge (Wii) @ 49.99
Item 7:
Computer Science pen @ 3.40
Item 8:
Rubik's cube @ 9.10
Item 9:
Computer Science Barbie @ 19.99
Item 10:
'Java Rules!' button @ 0.99 (10 for 5.00)
Item 11:
'Java Rules!' bumper sticker @ 0.99 (20 for 8.95)


Customer # 1 Shopping cart:
Item 1:
silly putty @ 3.95 (10 for 19.99)
Quantity: 10
Final Price: 19.99

Item 2:
Mario Computer Science Party 2 (Wii) @ 49.99
Quantity: 1
Final Price: 49.99

Item 3:
'Java Rules!' button @ 0.99 (10 for 5.00)
Quantity: 12
Final Price: 6.98

Item 4:
bottle o bubbles @ 0.99
Quantity: 6
Final Price: 5.94

Total: $ 82.90

Customer # 2 Shopping cart:
Item 1:
Computer Science pen @ 3.40
Quantity: 3
Final Price: 10.20

Item 2:
'Java Rules!' bumper sticker @ 0.99 (20 for 8.95)
Quantity: 20
Final Price: 8.95

Item 3:
bottle o bubbles @ 0.99
Quantity: 6
Final Price: 5.94

Total: $ 25.09


Customer # 3 Shopping cart:
Item 1:
bottle o bubbles @ 0.99
Quantity: 6
Final Price: 5.94

Item 2:
silly string @ 3.50 (10 for 14.95)
Quantity: 20
Final Price: 29.90

Total: $ 35.84


Customer # 4 Shopping cart:
Item 1:
Computer Science Barbie @ 19.99
Quantity: 0
Final Price: 0.00

Total: $ 0.00

Customer # 5 Shopping cart:
Item 1:
'Java Rules!' bumper sticker @ 0.99 (20 for 8.95)
Quantity: 12
Final Price: 11.88

Item 2:
Mario Computer Science Party 2 (Wii) @ 49.99
Quantity: 5
Final Price: 249.95

Item 3:
silly putty @ 3.95 (10 for 19.99)
Quantity: 9
Final Price: 35.55

Total: $ 297.38


Customer #5B Shopping cart:
Item 1:
'Java Rules!' bumper sticker @ 0.99 (20 for 8.95)
Quantity: 12
Final Price: 11.88

Item 2:
Mario Computer Science Party 2 (Wii) @ 49.99
Quantity: 5
Final Price: 249.95

Item 3:
silly putty @ 3.95 (10 for 19.99)
Quantity: 9
Final Price: 35.55

SubTotal: $ 297.38
Discount: $ 29.74
Total: $ 267.64

Explanation / Answer

import java.util.ArrayList;

class Item {
   String Name;
   double Price;
   int BulkQuantity;
   double BulkPrice;

   Item(String n, double p) {
       Name = n;
       if (p < 0) {
           throw new IllegalArgumentException("Price can't be negative");
       } else {
           Price = p;
       }
   }

   Item(String n, double p, int bQ, double bP) {
       Name = n;
       if (p < 0) {
           throw new IllegalArgumentException("Price can't be negative");
       } else {
           Price = p;
       }
      
       if (bQ < 0) {
           throw new IllegalArgumentException(
                   "Bulk Quantity can't be negative");
       } else
       {
           BulkPrice=bP;
           BulkQuantity = bQ;
       }

   }

   public double priceFor(int quantity)
   {
       if (quantity == 1) {
           return Price;
       } else if (quantity < 0) {
           throw new IllegalArgumentException("Quantity can't be negative");
       }
       else if(quantity==0)
       {
           return 0;
       }
       else if ((BulkQuantity == quantity)&&(BulkQuantity!=0))
       {
           return BulkPrice;
       }
       else if ((BulkQuantity < quantity)&&(BulkQuantity!=0))
       {
           int bQ=quantity / BulkQuantity;
           int nbQ=quantity % BulkQuantity;
           return (BulkPrice*bQ)+(nbQ*Price);
       }
       else
       {
           return Price * quantity;
       }
   }

   public String toString()
   {
       String str = Name + " @ " + Price;
       if (BulkPrice != 0) {
           str = str + " ( " + BulkQuantity + " for " + BulkPrice +" )";
       }
       return str;
   }

   public boolean equals(Object obj) {
       Item item = (Item) obj;
       if (!item.Name.equals(Name)) {
           return false;
       }
       if (!(item.Price != Price)) {
           return false;
       }
       if (!(item.BulkPrice != BulkPrice)) {
           return false;
       }
       if (!(item.BulkQuantity != BulkQuantity)) {
           return false;
       }
       return true;
   }
}

class Catalog {
   String Name;
   ArrayList<Item> list;

   public Catalog(String n) {
       Name = n;
       list = new ArrayList<Item>();
   }

   public void add(Item item) {
       list.add(item);
   }

   public int size() {
       return list.size();
   }

   public Item get(int index) {
       return list.get(index);
   }

   public String getName() {
       return Name;
   }

   public boolean equals(Object obj) {
       Catalog c = (Catalog) obj;
       if (!Name.equals(c.Name)) {
           return false;
       }
       if (list.size() != c.size()) {
           return false;
       }
       for (int i = 0; i < list.size(); i++) {
           if (!list.get(i).equals(c.list.get(i))) {
               return false;
           }
       }
       return true;
   }
}

class ItemOrder
{
   Item item;
   int Quantity;

   public ItemOrder(Item i, int q)
   {
       item = i;
       if (q < 0) {
           throw new IllegalArgumentException("Quantity can't be negative");
       } else {
           Quantity = q;
       }
   }

   public double getPrice()
   {
       return item.priceFor(Quantity);
   }

   public Item getItem() {
       return item;
   }

   public int getQuantity() {
       return Quantity;
   }

   public boolean equals(Object obj) {
       ItemOrder o = (ItemOrder) obj;
       if (Quantity != o.Quantity) {
           return false;
       }
       if (!item.equals(o.item)) {
           return false;
       }
       return true;
   }
}

class ShoppingCart {
   ArrayList<ItemOrder> list;
   double Discount;

   public ShoppingCart() {
       list = new ArrayList<ItemOrder>();
   }

   public void add(ItemOrder o) {
       int check = -1;
       for (int i = 0; i < list.size(); i++) {
           if (list.get(i).item.equals(o.item)) {
               list.add(i, o);
               check = 1;
               break;
           }
       }
       if (check == -1) {
           list.add(o);
       }
   }
   public void setDiscount(boolean value)
   {
       if(value)
       {
           Discount=0.1;
       }
       else
       {
           Discount=0;
       }
   }
  
   public double getTotal()
   {
       double price = 0;
       for (int i = 0; i < list.size(); i++) {
           price = price + list.get(i).getPrice();
       }
       return price;
   }

   public boolean equals(Object obj) {
       ShoppingCart c = (ShoppingCart) obj;
       if (list.size() != c.list.size()) {
           return false;
       }
       for (int i = 0; i < list.size(); i++) {
           if (!list.get(i).equals(c.list.get(i))) {
               return false;
           }
       }
       return true;
   }
  
}

public class Mukesh {
   public static void main(String[] args) {
       // Create store items for the CS-211 Gift Catalog
       Item item1 = new Item("silly putty", 3.95, 10, 19.99);
       Item item2 = new Item("silly string", 3.50, 10, 14.95);
       Item item3 = new Item("bottle o bubbles", 0.99);
       Item item4 = new Item("Nintendo Wii system", 389.99);
       Item item5 = new Item("Mario Computer Science Party 2 (Wii)", 49.99);
       Item item6 = new Item("Don Knuth Code Jam Challenge (Wii)", 49.99);
       Item item7 = new Item("Computer Science pen", 3.40);
       Item item8 = new Item("Rubik's cube", 9.10);
       Item item9 = new Item("Computer Science Barbie", 19.99);
       Item item10 = new Item("'Java Rules!' button", 0.99, 10, 5.0);
       Item item11 = new Item("'Java Rules!' bumper sticker", 0.99, 20, 8.95);

       // Now create the CS-211 Gift Catalog
       Catalog catalogList = new Catalog("CS-211 Gift Catalog");
       catalogList.add(item1);
       catalogList.add(item2);
       catalogList.add(item3);
       catalogList.add(item4);
       catalogList.add(item5);
       catalogList.add(item6);
       catalogList.add(item7);
       catalogList.add(item8);
       catalogList.add(item9);
       catalogList.add(item10);
       catalogList.add(item11);
       for(int i=0;i<catalogList.size();i++)
       {
           Item item=catalogList.get(i);
           System.out.println("Item "+(i+1)+" :");
           System.out.println(item.toString());
       }

       // Then create some orders to test the various
       ItemOrder order1A = new ItemOrder(item1, 10);
       ItemOrder order1B = new ItemOrder(item1, 9);
       ItemOrder order2 = new ItemOrder(item3, 6);
       ItemOrder order3A = new ItemOrder(item5, 1);
       ItemOrder order3B = new ItemOrder(item5, 5);
       ItemOrder order3C = new ItemOrder(item5, 0);
       ItemOrder order4 = new ItemOrder(item7, 3);
       ItemOrder order5 = new ItemOrder(item10, 12);
       ItemOrder order6A = new ItemOrder(item11, 12);
       ItemOrder order6B = new ItemOrder(item11, 20);
       ItemOrder order7 = new ItemOrder(item2, 20);
       ItemOrder order8 = new ItemOrder(item9, 0);

       // Next, create carts for five different customers.
       ShoppingCart cart1 = new ShoppingCart();
       cart1.add(order1A);
       cart1.add(order3A);
       cart1.add(order5);
       cart1.add(order2);
      
       ShoppingCart cart2 = new ShoppingCart();
       cart2.add(order4);
       cart2.add(order6B);
       cart2.add(order3B);
       cart2.add(order3C);
       cart2.add(order2);

       ShoppingCart cart3 = new ShoppingCart();
       cart3.add(order2);
       cart3.add(order7);

       ShoppingCart cart4 = new ShoppingCart();
       cart4.add(order8);

       ShoppingCart cart5 = new ShoppingCart();
       cart5.add(order6A);
       cart5.add(order3A);
       cart5.add(order3B);
       cart5.add(order1B);

       ShoppingCart[] carts = new ShoppingCart[] { cart1, cart2, cart3, cart4,
               cart5 };

       // Now display the results
       // First, display the CS-211 Gift Catalog
       System.out.println(catalogList.Name);

       // Now display each customer's cart
       int customerNmbr = 1;
       for (ShoppingCart cart : carts)
       {
           System.out.println(" Customer # " + customerNmbr+" Shopping Cart: ");
           for(int i=0;i<cart.list.size();i++)
           {
               ItemOrder o=cart.list.get(i);
               System.out.println("Item "+(i+1)+":");
               System.out.println(o.item.toString());
               System.out.println("Quantity: "+o.Quantity);
               System.out.println("Final Price: "+o.getPrice()+" ");      
           }
           System.out.println("Total : $"+cart.getTotal());
           customerNmbr++;
           if(customerNmbr==5)
           {
               break;
           }
       }


       System.out.println(" Customer # " + customerNmbr+" Shopping Cart: ");
       for(int i=0;i<cart5.list.size();i++)
       {
           ItemOrder o=cart5.list.get(i);
           System.out.println("Item "+(i+1)+":");
           System.out.println(o.item.toString());
           System.out.println("Quantity: "+o.Quantity);
           System.out.println("Final Price: "+o.getPrice()+" ");      
       }
       System.out.println("Subtotal : $"+cart5.getTotal());
       cart5.setDiscount(true);
       System.out.println("Dicount : $"+cart5.getTotal()*cart5.Discount);
       System.out.println("Total Value : $"+cart5.getTotal()*(1+cart5.Discount));
      
      
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote