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);
}
}
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);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.