Could you help me and fix up and fill the things i need in the code. needs
Question:
Could you help me and fix up and fill the things i need in the code.
- needs to call toString() to display object data
- needs to have if statements to provide decision making
- mutator should be used to change object data
public Jersey(int p, String n, boolean s)
{
price = p;
name = n;
onSale = s;
}
public int getPrice()
{
return price;
}
public void setPrice(int p)
{
price = p;
}
public String getName()
{
return name;
}
public void setName(String n)
{
name = n;
}
public boolean getOnSale()
{
return onSale;
}
public void setOnSale(boolean s)
{
onSale = s;
}
public String toString()
{
return "Jersey
name: " + name + "
price: " + price + "
onSale: " + onSale;
}
Class 2: Hoodie
Attributes:
int price;
String name;
boolean onSale;
const int TAX_RATE = 7;
public Hoodie(int p, String n, boolean s)
{
price = p;
name = n;
onSale = s;
}
public int getPrice()
{
return price;
}
public void setPrice(int p)
{
price = p;
}
public String getName()
{
return name;
}
public void setName(String n)
{
name = n;
}
public boolean getOnSale()
{
return onSale;
}
public void setOnSale(boolean s)
{
onSale = s;
}
public String toString()
{
return
"Hoodie
name: " + name + "
price: " + price + "
onSale: " + onSale;
}
Main Class: Shopping
public class Shopping
{
public static void main(String[] args)
{
// create objects
Jersey j1 = new Jersey(50, "Soccer", false);
Hoodie h1 = new Hoodie(75, "Nike", true);
// display objects
System.out.println(j1);
System.out.println(h1);
// create scanner object
Scanner input = new Scanner(System.in);
// get user input
System.out.print("Enter the number of jerseys: ");
int numJerseys = input.nextInt();
System.out.print("Enter the number of hoodies: ");
int numHoodies = input.nextInt();
// calculate total
int total = (numJerseys * j1.getPrice()) + (numHoodies * h1.getPrice());
// display total
System.out.println("The total is: " + total);
}
}
Introduction to Data Mining
ISBN: 978-0321321367
1st edition
Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar