(Solved) : Part 1 Code Uestion Answered Let Us Know Got Helpful Answer Rate Answer Question Programmi Q29409821 . . .




This is part 1 of the code:
uestion has been answered
Let us know if you got a helpful answer. Rate thisanswer
Question: Programming Assignment #4 Assignment Objective Thisprogramming assignment will utilize Object Or…




Show transcribed image text
Expert Answer
AnonymousChegg expert answered this
Was this answer helpful?
1
0
1,849 answers
The project is lengthy. Given below is the code for Stage 1. Pleaseuse the following code to for Stage 2. Post the Stage 2 questionpart as a separate question with the following code.
DessertItem.java
==============
public abstract class DessertItem {
protected String name;
public DessertItem()
{
name = “”;
}
public DessertItem(String name1)
{
name = name1;
}
public String getName()
{
return name;
}
public void setName(String name1)
{
name = name1;
}
public abstract double getCost();
}
Candy.java
==========
public class Candy extends DessertItem {
private double weight;
private double pricePerPound;
public Candy()
{
super();
weight = 0;
pricePerPound = 0;
}
public Candy(String name, double w, double prc)
{
super(name);
weight = w;
pricePerPound = prc;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public double getPricePerPound() {
return pricePerPound;
}
public void setPricePerPound(double pricePerPound) {
this.pricePerPound = pricePerPound;
}
@Override
public double getCost() {
double total = weight * pricePerPound;
total = Math.round(total * 100);
return total;
}
public String toString()
{
String s = String.format(“%-50s $%.2fnt %.2f lbs @ $.2f”,getName(), getCost()/100, weight, pricePerPound);
return s;
}
}
Cookie.java
==========
public class Cookie extends DessertItem {
private int quantity;
private double pricePerDozen;
public Cookie()
{
super();
quantity = 0;
pricePerDozen = 0;
}
public Cookie(String name, int qty, double prc)
{
super(name);
quantity = qty;
pricePerDozen = prc;
}
public int getQuantity() {
return quantity;
}
public double getPricePerDozen() {
return pricePerDozen;
}
public void setPricePerDozen(double pricePerDozen) {
this.pricePerDozen = pricePerDozen;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
@Override
public double getCost() {
double total = pricePerDozen / 12 * quantity;
total = Math.round(total * 100);
return total;
}
public String toString()
{
String s = String.format(“%-50s $%.2fnt %d cookies @ $%.2f perDozen”, getName(), getCost()/100, quantity, pricePerDozen);
return s;
}
}
IceCream.java
===============
public class IceCream extends DessertItem{
private int numberOfScoops;
private double pricePerScoop;
private double toppingPrice;
public IceCream() {
super();
numberOfScoops = 0;
pricePerScoop = 0;
toppingPrice = 0;
}
public IceCream(String name, int scoops, double prcPerScoop,double toppings)
{
super(name);
numberOfScoops = scoops;
pricePerScoop = prcPerScoop;
toppingPrice = toppings;
}
public int getNumberOfScoops() {
return numberOfScoops;
}
public void setNumberOfScoops(int numberOfScoops) {
this.numberOfScoops = numberOfScoops;
}
public double getPricePerScoop() {
return pricePerScoop;
}
public void setPricePerScoop(double pricePerScoop) {
this.pricePerScoop = pricePerScoop;
}
public double getToppingPrice() {
return toppingPrice;
}
public void setToppingPrice(double toppingPrice) {
this.toppingPrice = toppingPrice;
}
@Override
public double getCost() {
double total = (numberOfScoops * pricePerScoop +toppingPrice);
return Math.round(100 * total );
}
public String toString()
{
String s = String.format(“%-50s $%.2fnt %d scoops @ $%.2f/scoop +$%.2f”, getName(), getCost()/100, numberOfScoops, pricePerScoop,toppingPrice);
return s;
}
}
DessertShop.java
===========
public class DessertShop {
public static void main(String[] args) {
Candy item1 = new Candy(“Peanut Butter Fudge”, 2.25, 3.99);
Cookie item2 = new Cookie(“Oatmeal Raisin Cookies”, 4, 3.99);
IceCream item3 = new IceCream(“Vanilla Ice Cream”, 2, 1.05,0.45);
System.out.println(item1);
System.out.println(item2);
System.out.println(item3);
}
}
output
======
Peanut Butter Fudge $8.98
2.25 lbs @ $.2f
Oatmeal Raisin Cookies $1.33
4 cookies @ $3.99 per Dozen
Vanilla Ice Cream $2.55
2 scoops @ $1.05/scoop + $0.45
Programming Assignment #4 Assignment Objective This programming assignment will utilize Object Oriented principles to develop an application called DessertShop. Stage 1: Develop Abstract Parent class and sub-classes using Inheritance The objective of the first stage of the project is to develop the proper implementation of an abstract parent class (Dessertltem) and the necessary derived classes (Candy, Cookie, and IceCream) implementing Inheritance. The user will develop the Dessert Shop application with the details below. Stage 1: Task(s) Class Definitions Define the Desserttem abstract superclass from which specific types of Dessertitem’s can be derived. This abstract class contains only one instance variable, name. This class must contain a default Constructor. This class must contain a constructor which can be used to pass in the name of the item This class must contain the getName() method to retrieve the name instance variable This class must contain the setName() method to set the name instance variable The class must contain an abstract method, getCost(), which is not defined in this class because determining the costs varies based on the type of the item. The Dessertshop application must contain a number of derived classes. The Candy class must be derived from the Dessertitem class. The Candy class contains only two instance variables: weight and pricePerPound. A Candy item has a weight and a price per pound which is used to determine its cost. For example, 2.30 lbs of fudge @ 0.89/Ib. = 205 cents. The cost must be rounded to the nearest cent. The Cookie class must be derived from the Dessertltem class. The Cookie class contains only two instance variables: itemCount and pricePerDozen. A Cookie item has a number and a price per dozen which are used to determine its cost. For example, 4 cookies @ 399 cents / dozen = 133 cents. The cost must be rounded to the nearest cent. The IceCream class must be derived from the Dessertltem class. The IceCream class contains only three instance variables: numberOfScoops, pricePerScoop and topping Price. The IceCream cost is determined by adding the topping Price to the total Ice Cream cost. The cost must be rounded to the nearest cent. Each class must contain constructors, which call the constructor of the superclass. Each class must implement a toString() method to provide a formatted output of the item and the price. The toString() must use the derived getCost() method to properly calculate the individual prices. 1 | Page Show transcribed image text
Expert Answer
Answer to Part 1 Code Uestion Answered Let Us Know Got Helpful Answer Rate Answer Question Programmi Q29409821 . . .
OR