Question

CSC 143 Weekly Exercise: Satisfying Slurps For thi

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

CoffeeShop.java

public class CoffeeShop {
   /**
   * @param args
   */
   public static void main(String[] args) {
       test();

   }

   public static void test() {
       Drinks d = new Drinks("Medium");
       Coffee c1 = new Coffee("Small", "Mocha");
       Tea t = new Tea("Medium", "Choco");
       Tea t1 = new Tea("Large", "Green");

       double totalCost = d.getPrice() + c1.getPrice() + t.getPrice()
               + t1.getPrice();

       System.out.println("Your order consists of:\n");
       System.out.println(d.toString());
       System.out.println(c1.toString());
       System.out.println(t.toString());
       System.out.println(t1.toString());

       System.out.println(String.format(
               "\nThe total cost of your order is: $%.2f", totalCost));
   }
}

Drinks.java

public class Drinks {
   private String name = "Water";
   protected double price_per_oz = 0.10;
   private String size = "Small";

   public Drinks(String s) {
       size = s;

   }

   public String toString() {
       String s = String.format(name + ", size: " + size + ", cost: $%.2f",
               getPrice());
       return s;
   }

   public double getPrice() {
       if (size.equals("Small")) {
           return 6 * price_per_oz;
       } else if (size.equals("Medium")) {
           return 12 * price_per_oz;
       } else {
           return 16 * price_per_oz;
       }
   }

   public String getSize() {
       return size;
   }
}

Coffee.java

public class Coffee extends CaffeinatedDrinks {
   private String name = "Coffee";
   private String type = "Drip";
   private double price_surcharge_med = 0.50;
   private double price_surcharge_lar = 1.00;

   public Coffee(String s, String t) {
       super(s);
       type = t;
   }

   public String toString() {
       String s = String.format(
               name + ", type: " + type + ", size: " + super.getSize()
                       + ", cost: $%.2f", getPrice());
       return s;
   }

   public double getPrice() {
       if (super.getSize().equals("Medium")) {
           return super.getPrice() + price_surcharge_med;
       } else if (super.getSize().equals("Large")) {
           return super.getPrice() + price_surcharge_lar;
       } else {
           return super.getPrice();
       }
   }
}

Tea.java

public class Coffee extends CaffeinatedDrinks {
   private String name = "Coffee";
   private String type = "Drip";
   private double price_surcharge_med = 0.50;
   private double price_surcharge_lar = 1.00;

   public Coffee(String s, String t) {
       super(s);
       type = t;
   }

   public String toString() {
       String s = String.format(
               name + ", type: " + type + ", size: " + super.getSize()
                       + ", cost: $%.2f", getPrice());
       return s;
   }

   public double getPrice() {
       if (super.getSize().equals("Medium")) {
           return super.getPrice() + price_surcharge_med;
       } else if (super.getSize().equals("Large")) {
           return super.getPrice() + price_surcharge_lar;
       } else {
           return super.getPrice();
       }
   }
}

Tea.java

public class Tea extends CaffeinatedDrinks {
   private String name = "Tea";
   private String type = "English Breakfast";

   public Tea(String s, String t) {
       super(s);
       type = t;
   }

   public String toString() {
       String s = String.format(
               name + ", type: " + type + ", size: " + super.getSize()
                       + ", cost: $%.2f", getPrice());
       return s;
   }

   public double getPrice() {
       if (super.getSize().equals("Large")) {
           return super.getPrice() - (4 * 3 * price_per_oz);
       } else {
           return super.getPrice();
       }
   }
}

CaffeinatedDrinks.java

public class CaffeinatedDrinks extends Drinks {

   public CaffeinatedDrinks(String s) {
       super(s);
   }

   public String toString() {
       return super.toString();

   }

   public double getPrice() {
       return super.getPrice() * 3;

   }
}

NonCaffeinatedDrinks.java

public class NonCaffeinatedDrinks extends Drinks {

   public NonCaffeinatedDrinks(String s) {
       super(s);
   }

   public String toString() {
       return super.toString();

   }

   public double getPrice() {
       return super.getPrice() * 2;

   }
}


Problems Javadoc DeclarationConsole 3 «terminated> Coffeeshop Java Application C:\Program Files Javalre7 bin yavaw.exe Jan 19

Add a comment
Know the answer?
Add Answer to:
CSC 143 Weekly Exercise: Satisfying Slurps For this assignment, imagine you have been hired to create...
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
  • Wolfie's Car Repair Shop For this assignment you will be completing a program that manages cars...

    Wolfie's Car Repair Shop For this assignment you will be completing a program that manages cars and car repairs at Wolfie's Car Repair Shop. The program is menu-driven. The menu can be found in Homework.Driver.java. Provided in that file is a series of methods that begin with the prefix main_. Those methods request input from the user and then call methods from the class CarRepairShop. It is these methods in the CarRepairShop that you will be implementing for homework. In...

  • Order up:: Write a program that will be used to keep track of orders placed at...

    Order up:: Write a program that will be used to keep track of orders placed at a donut shop. There are two types of items that can be ordered: coffee or donuts. Your program will have a class for each order type, and an abstract superclass. Coffee orders are constructed with the following information: quantity (int) - how many coffees are being ordered size (String) - the size of the coffees (all coffees in the order have the same size)...

  • Description: You have been asked to help the College of IST Running Club by designing a...

    Description: You have been asked to help the College of IST Running Club by designing a program to help them keep track of runners in the club, the races that will occur, and each runner's performance in each race! Requirements: Please use Java to implement the program Your program must: Store information about each Runner. Store information about each Race. Store information about the performance of each runner in each race that they compete in. Note that each race may...

  • Last picture is the tester program! In this Assignment, you will create a Student class and...

    Last picture is the tester program! In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPerson. The details of these classes are in the UML diagram below: UHPerson - name : String - id : int + setName(String) : void + getName(): String + setID(int) : void + getID(): int + toString(): String Faculty Student - facultyList : ArrayList<Faculty - rank: String -office Hours : String - studentList...

  • HELP....ITS CLOSING TONIGHT INFSCI 0017 – Assignment 4 You are doing an internship in a company...

    HELP....ITS CLOSING TONIGHT INFSCI 0017 – Assignment 4 You are doing an internship in a company specialized in create role-­‐playing computer games. As a part of the programming team, you are asked to implement and test the first version of a RolePlayer class. In the game, a RolePlayer is a knight with the mission of fight and kill monsters: vampires and werewolves. As the player defeat monsters, he/she gains points. The player is considered trainee if he/she has less than...

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
ADVERTISEMENT