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

Using Jgrasp Please help me create a new class (new file) \"ShoppingCart\" Instr

ID: 3827920 • Letter: U

Question

Using Jgrasp Please help me create a new class (new file) "ShoppingCart" Instructions are taken within the picture but its building base off of the class i posted named "Item".

I believe this is compositions and object oriented And no imports please try to keep it simple with only loops.

//John Ngan's Assignment five
public class Item {
//variables
private String name;
private String vendor;
private double salePrice;
private double costPrice;
private double weight;
private boolean taxable;

//Constructor
public Item(String n,double cp, double sp)
{
name=n;
costPrice=cp;
salePrice=sp;
weight=1;
taxable=true;
}

//toString part 1 Assignment 6
public String toString()
{
String Chair;
Chair = "Name : "+getName()+"Cost Price : "+getCostPrice()+"Sale Price : "+getSalePrice()+"Weight : "+getWeight()+"Taxable : "+getTaxable();
return Chair;
}


//Accessors
public String getName()
{
return name;
}
public String getVendor()
{
return vendor;
}
public double getSalePrice()
{
return salePrice;
}
public double getCostPrice()
{
return costPrice;
}
public double getWeight()
{
return weight;
}
public boolean getTaxable()
{
return taxable;
}



  
//mutuators
public void setVendor(String v)
{
vendor=v;
}
public void setWeight(double w)
{
weight=w;
}
public void setTaxable(boolean tax)
{
taxable=tax;
}
//increaseCost
public void increaseCost()
{
costPrice=costPrice+1;
}
//profit
public double profit()
{
return salePrice-costPrice;
}
public static void main(String[] args) {

//ItemTester?
Item chair = new Item("Desk Chair", 30, 55);
//increase cost price by $3.
chair.increaseCost();
chair.increaseCost();
chair.increaseCost();
//display the profit
System.out.println("The chair's profit is now $" + chair.profit());
//set the chair’s weight to 7 lb
chair.setWeight(7);

Item table = new Item("Picnic Table", 70,88);
table.setWeight(8);
System.out.println("The table's profit is now $" + table.profit());


//part 2 assignment 6
int totalWeight = 0;
Item []arrayItem = new Item[3];
arrayItem[0] = chair;
arrayItem[1] = table;
arrayItem[2] = chair;


for(int i = 0; i<arrayItem.length; i++){
totalWeight += arrayItem[i].getWeight();
}
System.out.println("The total weight of the chairs and table is "+totalWeight);
System.out.println(chair);

}
}

Design a Shoppingcart class that contains Items. This uses composition since there is an array of Item objects inside a Shoppingcart. Several interesting methods are addItem to insert an item to the cart. This is a void method since it modifies the state of the array in the Shoppingcart object. There are different ways to implement this method. One was is to have a single parameter that is an already constructed Item Another way is to have a set of parameters that are the parameters to the constructor of the Item class. cartTotal computes the total price of the cart. This method returns a double but does not need any parameters since it works with data members of the Shoppingcart object. mount receives the tax rate and computes the total tax to charge for the items currently in the cart. Only Taxable items should be considered for this calculation. This method also returns a double but does not need cart laxA any parameters since it works with data members of the ShoppingCart object For simplicity, you can assume that the capacity of a Shoppingcart is fixed at 10 items Keep in mind: Each class should have at least one constructor that receives arguments. Make data members private and create accessor and mutator methods whenever necessary. d har to Str d that y to display th f th

Explanation / Answer

private String name;
private String vendor;
private double salePrice;
private double costPrice;
private double weight;
private boolean taxable;

//Constructor
public Item(String n,double cp, double sp)
{
name=n;
costPrice=cp;
salePrice=sp;
weight=1;
taxable=true;
}

//toString part 1 Assignment 6
public String toString()
{
String Chair;
Chair = "Name : "+getName()+"Cost Price : "+getCostPrice()+"Sale Price : "+getSalePrice()+"Weight : "+getWeight()+"Taxable : "+getTaxable();
return Chair;
}


//Accessors
public String getName()
{
return name;
}
public String getVendor()
{
return vendor;
}
public double getSalePrice()
{
return salePrice;
}
public double getCostPrice()
{
return costPrice;
}
public double getWeight()
{
return weight;
}
public boolean getTaxable()
{
return taxable;
}



  
//mutuators
public void setVendor(String v)
{
vendor=v;
}
public void setWeight(double w)
{
weight=w;
}
public void setTaxable(boolean tax)
{
taxable=tax;
}
//increaseCost
public void increaseCost()
{
costPrice=costPrice+1;
}
//profit
public double profit()
{
return salePrice-costPrice;
}
public static void main(String[] args) {

//ItemTester?
Item chair = new Item("Desk Chair", 30, 55);
//increase cost price by $3.
chair.increaseCost();
chair.increaseCost();
chair.increaseCost();
//display the profit
System.out.println("The chair's profit is now $" + chair.profit());
//set the chair’s weight to 7 lb
chair.setWeight(7);

Item table = new Item("Picnic Table", 70,88);
table.setWeight(8);
System.out.println("The table's profit is now $" + table.profit());


//part 2 assignment 6
int totalWeight = 0;
Item []arrayItem = new Item[3];
arrayItem[0] = chair;
arrayItem[1] = table;
arrayItem[2] = chair;


for(int i = 0; i<arrayItem.length; i++){
totalWeight += arrayItem[i].getWeight();
}
System.out.println("The total weight of the chairs and table is "+totalWeight);
System.out.println(chair);

}
}

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