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

Create the following three classes : CafeDemo put it in a package named cafecom

ID: 3714699 • Letter: C

Question

Create the following three classes:

CafeDemo put it in a package named cafecom

public class CafeDemo {

    public static void main(String[] args) {

     CoffeeCup cupOne = new CoffeeCup(2.85, "Tall");

     CoffeeCup cupTwo = new CoffeeCup(1.95, "Short");

     Cafe Starbucks = new Cafe();

     CoffeeCup [] cups = {cupOne, cupTwo};

   System.out.println("Total Cost is: " +    

                             Starbucks.getTotalCost(cups));

     System.out.println(Starbucks.getMessage());

    }

}

Cafe put it in a package named cafecom

Cafe

-totalCost: double

- message: String

+getTotalCost(Cup[]):double

+getMessage(): String    

CoffeeCup put it in a package named coffeecupcom

CoffeeCup

-price: double

-size: String

+getPrice():double

+getSize():String

When you run the CafeDemo class, the following output will be produced:

Total Cost is: 4.80

Thank you for visiting Starbucks

You should implement all methods in classes Cafe and CoffeeCup, and add any necessary constructors.

You are not allowed to make any modifications to the CafeDemo class

Cafe

-totalCost: double

- message: String

+getTotalCost(Cup[]):double

+getMessage(): String    

Explanation / Answer

CafeDemo.java

public class CafeDemo {

public static void main(String[] args) {

CoffeeCup cupOne = new CoffeeCup(2.85, "Tall");

CoffeeCup cupTwo = new CoffeeCup(1.95, "Short");

Cafe Starbucks = new Cafe();

CoffeeCup [] cups = {cupOne, cupTwo};

System.out.println("Total Cost is: " +   

Starbucks.getTotalCost(cups));

System.out.println(Starbucks.getMessage());

}

}

Cafe.java

public class Cafe {

private double totalCost;

private String message;

public Cafe() {

}

public double getTotalCost(CoffeeCup c[]) {

for(CoffeeCup c1: c) {

totalCost+=c1.getPrice();

}

message="Thank you for visiting Starbucks";

return totalCost;

}

public String getMessage() {

return message;

}

}

CoffeeCup.java

public class CoffeeCup {

private double price;

private String size;

public CoffeeCup(double p , String s) {

this.size=s;

this.price=p;

}

public double getPrice() {

return price;

}

public String getSize() {

return size;

}

}

Output::

Total Cost is: 4.8
Thank you for visiting Starbucks

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