Question

In Java Pls

Class Design: Donut (Suggested Time Spent: < 15 minutes) The Donut class is intended to be an abstract and simplified represeClass Design: DonutBox (Suggested Time Spent: < 15 minutes) The DonutBox class is intended to be an abstract and simplified rDriver Class: DonutBox Driver (Suggested Time Spent: < 10 minutes) The DonutBoxDriver class is intended to be a simple driver

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Donut.java


import java.util.Objects;


public class Donut
{
private String name,type;
private double price;

public Donut()
{
name="Classic";
type="Plain";
price=0.99;
}

public Donut(String name, String type) {
this.name = name;
this.type = type;
if(type.equalsIgnoreCase("Plain"))
price=0.99;
else if(type.equalsIgnoreCase("Filled"))
price=1.29;
else if(type.equalsIgnoreCase("Glazed"))
price=1.49;
}

@Override
public String toString() {
return "Donut{" + "name=" + name + ", type=" + type + ", price=" + price + '}';
}


@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Donut other = (Donut) obj;
if (!Objects.equals(this.name, other.name)) {
return false;
}
if (!Objects.equals(this.type, other.type)) {
return false;
}
return true;
}

public String getName() {
return name;
}

public String getType() {
return type;
}

public double getPrice() {
return price;
}

private void setPrice(double price) {
this.price = price;
}

private void setName(String name) {
this.name = name;
}

private void setType(String type) {
this.type = type;
}
}

DonutBox.java


public class DonutBox
{
private Donut []Donuts;
private int count;

public DonutBox()
{
Donuts=new Donut[12];
count=0;
}

public int getCount() {
return count;
}
  
public void addDonut(Donut order)
{
Donuts[count++]=order;
}
public double getPrice()
{
double discount;
if(count<6)
discount=0;
else if(count>=6 && count<12)
discount=0.10;
else
discount=0.20;
double sum=0;
for(int i=0;i<count;i++)
{
sum+=Donuts[i].getPrice();
}
sum-=discount*sum;
return sum;
}

@Override
public String toString() {
String str="";
str="Donut Box:\n";
for(int i=0;i<count;i++)
{
str+=Donuts[i].toString()+"\n";
}
return str;
}
  
}
DonutBoxDriver.java


import java.text.DecimalFormat;


public class DonutBoxDriver {

private static DecimalFormat df2 = new DecimalFormat("#.##");
public static void main(String[] args)
{
DonutBox box1=new DonutBox();
box1.addDonut(new Donut("Bavarian Kreme", "Filled"));
  
DonutBox box2=new DonutBox();
box2.addDonut(new Donut("Bavarian Kreme", "Filled"));
box2.addDonut(new Donut("Bavarian Kreme", "Plain"));
box2.addDonut(new Donut("Strawberry-Frosted", "Glazed"));
  
DonutBox box3=new DonutBox();
box3.addDonut(new Donut("Bavarian Kreme", "Filled"));
box3.addDonut(new Donut("Bavarian Kreme", "Plain"));
box3.addDonut(new Donut("Strawberry-Frosted", "Glazed"));
box3.addDonut(new Donut("Jelly Donut", "Filled"));
box3.addDonut(new Donut("Bavarian Kreme", "Plain"));
box3.addDonut(new Donut("Bavarian Kreme", "Filled"));
box3.addDonut(new Donut("Cinnamon-Sugar", "Plain"));
box3.addDonut(new Donut("Strawberry-Frosted", "Glazed"));
  
DonutBox box4=new DonutBox();
box4.addDonut(new Donut("Bavarian Kreme", "Filled"));
box4.addDonut(new Donut("Bavarian Kreme", "Plain"));
box4.addDonut(new Donut("Strawberry-Frosted", "Glazed"));
box4.addDonut(new Donut("Jelly Donut", "Filled"));
box4.addDonut(new Donut("Bavarian Kreme", "Plain"));
box4.addDonut(new Donut("Bavarian Kreme", "Filled"));
box4.addDonut(new Donut("Cinnamon-Sugar", "Plain"));
box4.addDonut(new Donut("Strawberry-Frosted", "Glazed"));
box4.addDonut(new Donut("Strawberry-Frosted", "Glazed"));
box4.addDonut(new Donut("Chocolate Kreme", "Filled"));
box4.addDonut(new Donut("Bavarian Kreme", "Plain"));
box4.addDonut(new Donut("Marble-Frosted ", "Filled"));

  
System.out.println("Box 1:\n"+box1);
System.out.println("Total price: $"+df2.format(box1.getPrice()));
System.out.println("\nBox 2:\n"+box2);
System.out.println("Total price: $"+df2.format(box2.getPrice()));
System.out.println("\nBox 3:\n"+box3);
System.out.println("Total price: $"+df2.format(box3.getPrice()));
System.out.println("Box 4:\n"+box4);
System.out.println("Total price: $"+df2.format(box4.getPrice()));
  
}
  
}

outputsDonut class NetBeans IDE 8.0.1 aSearch (Cti 41) File Edit View Navigate Source Refactor Run Debug Profile Team Iools Window HDonut class NetBeans IDE 8.0.1 aSearch (Cti 41) File Edit View Naevigate Source Refactor Run Debug Profile Teem Iools Window

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
In Java Pls Class Design: Donut (Suggested Time Spent: < 15 minutes) The Donut class is intended to be an abstract a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING JAVA, Class Design: Person The Person class is intended to be an abstract and simplified representation of a pers...

    USING JAVA, Class Design: Person The Person class is intended to be an abstract and simplified representation of a person. Each person will have an array of "friends" - which are other "Person" instances. Data to Store (2 Points) Name private instance variable with only private setter (2 Points) Friends private instance array with neither getter nor setter Actions Constructor o 1 Point) Take in as argument the name of the person (enforce invariants) o (1 Point) Initialize the array...

  • JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class...

    JAVA Problem:  Coffee    Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...

  • Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named...

    Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...

  • In Java PLS HW7: Feature Comparison CSS 142 Computer Programming 1 By: Hansel Ong Summary With so many options for most...

    In Java PLS HW7: Feature Comparison CSS 142 Computer Programming 1 By: Hansel Ong Summary With so many options for most anything nowadays (phones, cars, hotels, schools, courses, etc.) consumers have become accustomed to selecting a few objects (e.g. smart watches) to compare the features. Write a simple "Device" class with a few features that could be used to compare Device instances and a Driver class with which to test/drive this "Device" class. Skills Expected All the skills from previous...

  • Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEm...

    Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains...

    Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains instance data that represents the dog's name and dog's age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in "person years" (seven times age of dog. Include a toString method that returns a one-time description of the dog (example below)....

  • In Java* Please implement a class called "MyPet". It is designed as shown in the following...

    In Java* Please implement a class called "MyPet". It is designed as shown in the following class diagram. Four private instance variables: name (of the type String), color (of the type String), gender (of the type char) and weight(of the type double). Three overloaded constructors: a default constructor with no argument a constructor which takes a string argument for name, and a constructor with take two strings, a char and a double for name, color, gender and weight respectively. public...

  • cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher,...

    cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher, price, and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Include a toString method that returns a nicely formatted, multi-line description of the book. Write another class called Bookshelf, which has name and array of Book objects. Bookself capacity is maximum of five books. Includes method for Bookself that adds, removes,...

  • java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectang...

    java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT