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

A)Complete Java class that can be used to create a Product object as described b

ID: 3573480 • Letter: A

Question

A)Complete Java class that can be used to create a Product object as described below. * A pro duct has-a: * Product name * Product cost * Amount of product in stock (as a whole number) * Add all instance variables * The class must have getters and setters for all instance variables * The class must have two constructors, a no-args and a constructor that receives input parameters for each instance variable. * Add a method which changes the price of the product by a given percent: public void markdown(double byPercent) The markdown method is used to change the price of the product prior to putting it on sale
B) DairyProduct and ProduceProduct, that extend the class, P roduct (from part A):
DairyProduct has-an instance variable, containsLactose, of type boolean which indicates whether it contains lactose or not. * ProduceProduct has-an instance variable, fruitOrVegetable, of type String which indicates whether the product is a fruit or a vegetable. * Write both a no-args and a constructor that requires input for name, price and amount in stock for both classes. * Write getters and setters for all instance variables for both classes.

A)Complete Java class that can be used to create a Product object as described below. * A pro duct has-a: * Product name * Product cost * Amount of product in stock (as a whole number) * Add all instance variables * The class must have getters and setters for all instance variables * The class must have two constructors, a no-args and a constructor that receives input parameters for each instance variable. * Add a method which changes the price of the product by a given percent: public void markdown(double byPercent) The markdown method is used to change the price of the product prior to putting it on sale
B) DairyProduct and ProduceProduct, that extend the class, P roduct (from part A):
DairyProduct has-an instance variable, containsLactose, of type boolean which indicates whether it contains lactose or not. * ProduceProduct has-an instance variable, fruitOrVegetable, of type String which indicates whether the product is a fruit or a vegetable. * Write both a no-args and a constructor that requires input for name, price and amount in stock for both classes. * Write getters and setters for all instance variables for both classes.

A)Complete Java class that can be used to create a Product object as described below. * A pro duct has-a: * Product name * Product cost * Amount of product in stock (as a whole number) * Add all instance variables * The class must have getters and setters for all instance variables * The class must have two constructors, a no-args and a constructor that receives input parameters for each instance variable. * Add a method which changes the price of the product by a given percent: public void markdown(double byPercent) The markdown method is used to change the price of the product prior to putting it on sale
B) DairyProduct and ProduceProduct, that extend the class, P roduct (from part A):
DairyProduct has-an instance variable, containsLactose, of type boolean which indicates whether it contains lactose or not. * ProduceProduct has-an instance variable, fruitOrVegetable, of type String which indicates whether the product is a fruit or a vegetable. * Write both a no-args and a constructor that requires input for name, price and amount in stock for both classes. * Write getters and setters for all instance variables for both classes. B) DairyProduct and ProduceProduct, that extend the class, P roduct (from part A):
DairyProduct has-an instance variable, containsLactose, of type boolean which indicates whether it contains lactose or not. * ProduceProduct has-an instance variable, fruitOrVegetable, of type String which indicates whether the product is a fruit or a vegetable. * Write both a no-args and a constructor that requires input for name, price and amount in stock for both classes. * Write getters and setters for all instance variables for both classes.

Explanation / Answer


public class product
{
   private String productName_;
   private double cost_;
   private int amountOfProductInStock_;
  
   public product() {
       productName_ = "";
       cost_ = 0.0;
       amountOfProductInStock_ = 0;
   }
  
   public product(String name, double cost, int amtOfProduct) {
       productName_ = name;
       cost_ = cost;
       amountOfProductInStock_ = amtOfProduct;
   }  

public void setProductName(String name) {
       productName_ = name;
   }
  
   public String getProductName() {
       return productName_;
   }
  
   public void setCost(double cost) {
       cost_ = cost;
   }
  
   public double getCost() {
       return cost_;
   }
  
   public void setAmountOfProductInStock(int amtOfProduct) {
       amountOfProductInStock_ = amtOfProduct;
   }
  
   public int getAmountOfProductInStock() {
       return amountOfProductInStock_;
   }
  
   public void markdown(double byPercent) {
       cost_ = cost_-((byPercent/100)*cost_);
   }
  
   public static void main(String[] args)
   {
       /* write your code here */
   }
}

public class DairyProduct extends product {

private boolean containsLactose_;

public DairyProduct() {
containsLactose_ = false;
}

public DairyProduct(boolean containsLactose) {
containsLactose_ = containsLactose;
}

public void setContainsLactose(boolean containsLactose) {
containsLactose_ = containsLactose;
}

public boolean getContainsLactose() {
return containsLactose_;
}
}


public class ProduceProduct extends product {

private String fruitOrVegetable_;

public ProduceProduct() {
fruitOrVegetable_ = "";
}


public ProduceProduct(String fruitOrVegetable) {
fruitOrVegetable_ = fruitOrVegetable;
}

public void setFruitOrVegetable(String fruitOrVegetable) {
fruitOrVegetable_ = fruitOrVegetable;
}

public String getFruitOrVegetable() {
return fruitOrVegetable_;
}
}

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