Question

In: Computer Science

Programming language: Java If any more information is needed please let me know exactly what you...

Programming language: Java

If any more information is needed please let me know exactly what you need.

Though there are a bunch of files they are small and already done. Modify the driver file ,Starbuzz coffee, to be able to order each blend and be able to add each condiment to each of the blends. The price should be set accordingly. Be able to: order 1 of each type of beverage, add multiple toppings to each ordered beverage and use each condiment at least once.

Beverage.java:

public abstract class Beverage {
   String description = "Unknown Beverage";
  
   public String getDescription() {
       return description;
   }

   public abstract double cost();
}

CondimentDecorator.java:

public abstract class CondimentDecorator extends Beverage {
   public abstract String getDescription();
}

DarkRoast.java:

public class DarkRoast extends Beverage {
   public DarkRoast() {
       description = "Dark Roast Coffee";
   }

   public double cost() {
       return .99;
   }
}

Decaf.java:

public class Decaf extends Beverage {
   public Decaf() {
       description = "Decaf Coffee";
   }

   public double cost() {
       return 1.05;
   }
}

Espresso.java:

public class Espresso extends Beverage {
  
   public Espresso() {
       description = "Espresso";
   }
  
   public double cost() {
       return 1.99;
   }
}

HouseBlend.java:

public class HouseBlend extends Beverage {
   public HouseBlend() {
       description = "House Blend Coffee";
   }

   public double cost() {
       return .89;
   }
}

Caramel.java:

public class Caramel extends Beverage {
   public Caramel() {
       description = "Caramel Coffee";
   }

   public double cost() {
       return 1.35;
   }
}

Chocolate.java:

public class Chocolate extends CondimentDecorator {
   Beverage beverage;

   public Chocolate(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Chocolate";
   }

   public double cost() {
       return .20 + beverage.cost();
   }
}

Cinnamon.java:

public class Cinnamon extends CondimentDecorator {
   Beverage beverage;

   public Cinnamon(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Cinnamon";
   }

   public double cost() {
       return .15 + beverage.cost();
   }
}

Milk.java:

public class Milk extends CondimentDecorator {
   Beverage beverage;

   public Milk(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Milk";
   }

   public double cost() {
       return .10 + beverage.cost();
   }
}

Mint.java:

public class Mint extends CondimentDecorator {
   Beverage beverage;

   public Mint(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Mint";
   }

   public double cost() {
       return .15 + beverage.cost();
   }
}

Mocha.java:

public class Mocha extends CondimentDecorator {
   Beverage beverage;

   public Mocha(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Mocha";
   }

   public double cost() {
       return .20 + beverage.cost();
   }
}

Soy.java:

public class Soy extends CondimentDecorator {
   Beverage beverage;

   public Soy(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Soy";
   }

   public double cost() {
       return .15 + beverage.cost();
   }
}

Whip.java:

public class Whip extends CondimentDecorator {
   Beverage beverage;

   public Whip(Beverage beverage) {
       this.beverage = beverage;
   }

   public String getDescription() {
       return beverage.getDescription() + ", Whip";
   }

   public double cost() {
       return .10 + beverage.cost();
   }
}

StarbuzzCoffee.java:

public class StarbuzzCoffee {

   public static void main(String args[]) {
       Beverage beverage = new Espresso();
       System.out.println(beverage.getDescription()
               + " $" + beverage.cost());
              
       Beverage beverage1 = new Decaf();
       beverage1 = new Soy(beverage1);
       beverage1 = new Mocha(beverage1);
       beverage1 = new Whip(beverage1);
       beverage1 = new Cinnamon(beverage1);
       beverage1 = new Mint(beverage1);
       beverage1 = new Chocolate(beverage1);
       System.out.println(beverage1.getDescription()
               + " $" + beverage1.cost());

       Beverage beverage2 = new DarkRoast();
       beverage2 = new Soy(beverage2);
       beverage2 = new Mocha(beverage2);
       beverage2 = new Whip(beverage2);
       beverage2 = new Cinnamon(beverage2);
       beverage2 = new Mint(beverage2);
       beverage2 = new Chocolate(beverage2);
       System.out.println(beverage2.getDescription()
               + " $" + beverage2.cost());

       Beverage beverage3 = new HouseBlend();
       beverage3 = new Soy(beverage3);
       beverage3 = new Mocha(beverage3);
       beverage3 = new Whip(beverage3);
       beverage3 = new Cinnamon(beverage3);
       beverage3 = new Mint(beverage3);
       beverage3 = new Chocolate(beverage3);
       System.out.println(beverage3.getDescription()
               + " $" + beverage3.cost());
      
       Beverage beverage4 = new Hazelnut();
       beverage4 = new Soy(beverage4);
       beverage4 = new Mocha(beverage4);
       beverage4 = new Whip(beverage4);
       beverage4 = new Cinnamon(beverage4);
       beverage4 = new Mint(beverage4);
       beverage4 = new Chocolate(beverage4);
       System.out.println(beverage4.getDescription()
               + " $" + beverage4.cost());  

       Beverage beverage5 = new Caramel();
       beverage5 = new Soy(beverage5);
       beverage5 = new Mocha(beverage5);
       beverage5 = new Whip(beverage5);
       beverage2 = new Cinnamon(beverage5);
       beverage2 = new Mint(beverage5);
       beverage2 = new Chocolate(beverage5);
       System.out.println(beverage5.getDescription()
               + " $" + beverage5.cost());
   }
}

Solutions

Expert Solution

After modifying the StarbuzzCoffee.java

import java.util.*;
public class Main {

   public static void main(String args[]) {
       Scanner sc=new Scanner(System.in);
       Beverage beverage = new Espresso();
       System.out.println(beverage.getDescription()
               + " $" + beverage.cost());
              
       Beverage beverage1 = new Decaf();
       beverage1 = new Soy(beverage1);
       beverage1 = new Mocha(beverage1);
       beverage1 = new Whip(beverage1);
       beverage1 = new Cinnamon(beverage1);
       beverage1 = new Mint(beverage1);
       beverage1 = new Chocolate(beverage1);
       System.out.println(beverage1.getDescription()
               + " $" + beverage1.cost());

       Beverage beverage2 = new DarkRoast();
       beverage2 = new Soy(beverage2);
       beverage2 = new Mocha(beverage2);
       beverage2 = new Whip(beverage2);
       beverage2 = new Cinnamon(beverage2);
       beverage2 = new Mint(beverage2);
       beverage2 = new Chocolate(beverage2);
       System.out.println(beverage2.getDescription()
               + " $" + beverage2.cost());

       Beverage beverage3 = new HouseBlend();
       beverage3 = new Soy(beverage3);
       beverage3 = new Mocha(beverage3);
       beverage3 = new Whip(beverage3);
       beverage3 = new Cinnamon(beverage3);
       beverage3 = new Mint(beverage3);
       beverage3 = new Chocolate(beverage3);
       System.out.println(beverage3.getDescription()
               + " $" + beverage3.cost());
      
       Beverage beverage4 = new Hazelnut();
       beverage4 = new Soy(beverage4);
       beverage4 = new Mocha(beverage4);
       beverage4 = new Whip(beverage4);
       beverage4 = new Cinnamon(beverage4);
       beverage4 = new Mint(beverage4);
       beverage4 = new Chocolate(beverage4);
       System.out.println(beverage4.getDescription()
               + " $" + beverage4.cost());  

       Beverage beverage5 = new Caramel();
       beverage5 = new Soy(beverage5);
       beverage5 = new Mocha(beverage5);
       beverage5 = new Whip(beverage5);
       beverage2 = new Cinnamon(beverage5);
       beverage2 = new Mint(beverage5);
       beverage2 = new Chocolate(beverage5);
       System.out.println(beverage5.getDescription()
               + " $" + beverage5.cost());
        System.out.println("Coffee types: 1.Decaf Coffee  2.DarkRoast Coffee 3.HouseBlend Coffee 4. Hazelnut coffee 5.caramel Coffee");
        System.out.println("Select the type of coffee you want");
        int choice = sc.nextInt();
        double price=0;
        if (choice==1){
            price= beverage1.cost();
        }
        else if (choice==2){
             price=beverage2.cost();
        }
        else if(choice==3){
             price=beverage3.cost();
        }
        else if(choice==4){
             price=beverage4.cost();
        }
        else if(choice==5){
             price=beverage5.cost();
        }
        System.out.println("Do you want to add soy? Y/N");
        char c = sc.next().charAt(0);
                if(c=='y'||c=='Y'){
                    price=price+0.15;
                }
                System.out.println("Do you want to add Mocha? Y/N");
        c = sc.next().charAt(0);
                if(c=='y'||c=='Y'){
                    price=price+0.20;
                }
                System.out.println("Do you want to add Whip? Y/N");
        c = sc.next().charAt(0);
                if(c=='y'||c=='Y'){
                    price=price+0.15;
                }
                System.out.println("Do you want to add Cinnamon? Y/N");
        c = sc.next().charAt(0);
                if(c=='y'||c=='Y'){
                    price=price+0.15;
                }
                System.out.println("Do you want to add Mint? Y/N");
        c = sc.next().charAt(0);
                if(c=='y'||c=='Y'){
                    price=price+0.15;
                }
                System.out.println("Do you want to add Chocolate? Y/N");
        c = sc.next().charAt(0);
                if(c=='y'||c=='Y'){
                    price=price+0.20;
                }
                System.out.println("The total cost your coffee is:"+price);
   }
}

Output is as follows:


Related Solutions

question 1 (explain each code) If more information if needed please let me know a)t=linspace(0,1,1000); %...
question 1 (explain each code) If more information if needed please let me know a)t=linspace(0,1,1000); % Time t Meaning: b) for i=1:1000 xt(i)=v*cos(theta*pi/180)*t(i); yt(i)=h+(v*sin(theta*pi/180)*t(i))-0.5*g*t(i)^2; end Meaning: c) k = find(yt<0,1) % find index at which distance becomes fprintf('Ball hits the ground at distance of %d meters',xt(k)) Meaning: d) x=0:0.1:max(xt); y=0; plot(x,y*ones(size(x)),'--k') Meaning:
Use the article to answer these questions. Let me know if you need more information. What...
Use the article to answer these questions. Let me know if you need more information. What question was asked? Summarize the main points of the article—what is the primary goal or aim of the described study? How was the question asked? Summarize the main methods used in the study. What did the authors find? Summarize the major results of the study. How does this article provide background information for quorum sensing in gingivitis? Some possible questions you could address…How does...
Please answer in C++! Let me know if you have any questions about these. Program 1:...
Please answer in C++! Let me know if you have any questions about these. Program 1: For this program, imagine we want to track an object and detect if it goes off the left or right side of the screen (that is, it’s X position is less than 0 and greater than the width of the screen, say, 100). Write a program that asks the user for the starting X and Y position of the object as well as the...
Below is the only information I received for these questions. Please let me know if there...
Below is the only information I received for these questions. Please let me know if there is any additional info you may need. Any questions will help Federal Taxation I Module 8: Comprehensive Tax Return Project Jared and Ashley have come to you for help filing their 2018 tax return. They are married on December 31, 2018 and are both age 40. They live with their three qualifying children, Nick, Betty, and Roger, who are 12, 14, and 17 years...
Can you please solve this using recursion/ dynamic programming? Any programming language is fine. Wallace the...
Can you please solve this using recursion/ dynamic programming? Any programming language is fine. Wallace the Weightlifting Walrus is training for a contest where it will have to lift 1000 kg. Wallace has some weight plates lying around, possibly of different weights, and its goal is to add some of the plates to a bar so that it can train with a weight as close as possible to 1000 kg. In case there exist two such numbers which are equally...
Please answer everything in R programming language. Show the code to me as well. Thank You...
Please answer everything in R programming language. Show the code to me as well. Thank You 1. Problem Open dataset stat500. Package: faraway. Use R (a) Calculate the correlation matrix. 10. (b) Plot total vs hw, to see how strong the relationship. (c) Build a simple linear regression: total regressed against midterm. Print model output. (d) Calculate directly the coefficients as in (3) (e) Calculate the Residual standard error s, as in (4). (f) Calculate the standard error of beta_1,...
Give one example to non-regularity on any programming language that you know. Your should provide an...
Give one example to non-regularity on any programming language that you know. Your should provide an example to each one of the following categories: Generality, Orthogonality, and Uniformity. That is, you will give total three examples and explain why...
Let me know if the Adjusted trial balance on December 31, 20X6 is needed to answer...
Let me know if the Adjusted trial balance on December 31, 20X6 is needed to answer the below as I can provide it. Thank you! Questions 4 through 10 are based on the following December 31, 20X6 year-end account balances for XYZ Co. after adjusting entries had been prepared but before the books were closed for the year.                                                                  Cash……………..…………………………….250,000                 Accounts receivable…………………….……..680,000                 Marketable securities…………………………...60,000                 Prepaid insurance……………………………….35,000                 Prepaid rent….………………………………….30,000                 Office equipment…………………………….....620,000                 Accumulated depreciation: equipment………...200,000                 Land……………………………………………750,000                 Accounts payable………………………………306,000                 Dividends payable……………………………… 50,000                 Interest payable…………………………………......
Hello! Please let me know, thank you! You have a credit card with a balance of...
Hello! Please let me know, thank you! You have a credit card with a balance of $13,600 and an APR of 18 percent compounded monthly. You have been making monthly payments of $260 per month, but you have received a substantial raise and will increase your monthly payments to $335 per month. How many months quicker will you be able to pay off the account? 37.39 Months 36.05 Months 40.06 Months 11.71 Months 34.33 Months Thank you!
In JAVA Language Please! Programming Exercise 3.20 required you to design a PID manager that allocated...
In JAVA Language Please! Programming Exercise 3.20 required you to design a PID manager that allocated a unique process identifier to each process. Exercise 4.20 required you to modify your solution to Exercise 3.20 by writing a program that created a number of threads that requested and released process identifiers. Now modify your solution to Exercise 4.20 by ensuring that the data structure used to represent the availability of process identifiers is safe from race conditions. Use Pthreads mutex locks....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT