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

This assignment is an introduction to extending classes. it\'s very challenging

ID: 654975 • Letter: T

Question

This assignment is an introduction to extending classes. it's very challenging for a simple, 5 point weekly assignment. I understand the basic concept, but am stuggling to conceptualize how to bring it all together. Can someone help me? A complete solution including 5 classes and also a client class would be best, but anything will do. I'll be up all night trying to figure it out. Thanks in advance.

        
For this assignment, imagine you have been hired to create a program to manage drink orders at a local coffee shop. The coffee shop is known for changing their menu frequently, and people come to the shop in anticipation of getting unusual, but delicious, drinks. Since the drinks change so frequently, your program will need to have the flexibility to handle this. Accordingly, you decide to create classes that can be used to price drinks based on their common features, rather than creating a static look-up table of prices.

To demonstrate how your program will work to the coffee shop owner and employees, you want to design and demo a prototype of your idea. To do this, you must implement a Drinks.java Class and associated subclasses that will be utilized by a CoffeeShop.java Class (the driver, or client, class) to calculate the cost of an order of drinks. The output will be displayed in a java console. This assignment is intended to give you practice using inheritance.

The Drinks Class will contain fields for the base price/oz. and the drink size (small = 6 oz., medium = 12 oz., large = 16 oz.). In essence, this covers the minimal costs (labor, cup, etc.). It will include also methods to print the drink information and to change the base drink prices (ideally all the prices should be changed simultaneously).

A number of subclasses will extend the Drinks class. You are being asked to implement a CaffeinatedDrinks.java class and a NonCaffeinatedDrinks.java. Both of these classes extend the Drinks class. In addition, you are being asked to implement a Tea.java class and a Coffee.java class that extends the CaffeinatedDrinks class.  
Data for Sample Program:

Drinks Class:

Base Drink price: 10 cents/oz.

Default drink size = small (6 oz.)

------------------------------------------------------------------------------------------------------------------------------

CaffeinatedDrinks Class:

Base Drink price: 3 times the base price for the Drinks class

Default drink size = small (6 oz.)

-------------------------------------------------------------------------------------------------------------------------------

NonCaffeinatedDrinks Class:
Base Drink price: 2 times the base price for the Drinks class Default drink size = small (6 oz.)

----------------------------------------------------------------------------------------------------------------------------------

Coffee Class:
Base Drink price: Same as CaffeinatedDrinks class for small size, but a surcharge of 50 cents for medium and $1 for large to cover the cost of extra shots needed.

Default drink size = small (6 oz.)

Default drink type = drip

-----------------------------------------------------------------------------------------------------------------------------------------------

Tea Class:
Base Drink price: same as for CaffeinatedDrinks class, except no surcharge for larger sizes, as it is just adding more water.

Default drink size = small (6 oz.)

Default tea flavor = English Breakfast   

Here are the requirements:
Use the attached drink class hierarchy to organize your code.

Implement the classes to minimize code redundancy by extending superclasses. For this prototype, you can have the tea flavors and coffee drink types entered in as parameters. Future versions of the program might have a different way of handling this. Create a no-parameter constructor and a constructor that takes an appropriate number of parameters for each class. Write methods to return basic drink information (size and price for all drinks).

Also write the client Class CoffeeShop.java that demonstrates your classes and their methods. This class should contain a main method. I should be able to run your code without creating a new client!

Description of the client Class:
1. Should print a sample drink order

Explanation / Answer

Here's the solution. I am furnishing the code for all classes as specified. Please feel free to modify them accordingly:

Drinks.java

/**
*
*/
package com.test.coffeeshop;

/**
* Base class
* Holds the base price for the drink and also the size of the drink
*
*/
public class Drinks {
  
   public int basePricePerOz = 10;
   public int drinkSize = 6; //Initialize to small size by default
  
   /**
   * @return the basePricePerOz
   */
   public int getBasePricePerOz() {
       return basePricePerOz;
   }
   /**
   * @param basePricePerOz the basePricePerOz to set
   */
   public void setBasePricePerOz(int size) {
       this.basePricePerOz = 10;
   }
   /**
   * @return the drinkSize
   */
   public int getDrinkSize() {
       return drinkSize;
   }
   /**
   * @param drinkSize the drinkSize to set
   */
   public void setDrinkSize(int drinkSize) {
       this.drinkSize = drinkSize;
   }
  
   public void printDrinkInformation() {
       System.out.println("Base price : "+this.basePricePerOz+" cents per oz");
   }
}

CaffeinatedDrinks.java

package com.test.coffeeshop;

public class CaffeinatedDrinks extends Drinks {

   public int basePricePerOz = 3 * super.basePricePerOz;
   public int drinkSize = 6; //Initialize to small size by default
  
   public CaffeinatedDrinks(){
       super();
   }
}

Coffee.java

package com.test.coffeeshop;

public class Coffee extends CaffeinatedDrinks {
  
   public int basePricePerOz = super.basePricePerOz;
   public int drinkSize = 6; //Initialize to small size by default
   public String drinkType = "";
  
  
   /**
   * Constructor to instantiate the Coffee class
   * @param size
   * @param type
   */
   public Coffee(int size, String type) {
       super();
       this.drinkSize = size;
       this.drinkType = type;
   }
  
   /**
   * @return the drinkType
   */
   public String getDrinkType() {
       return drinkType;
   }

   /**
   * @param drinkType the drinkType to set
   */
   public void setDrinkType(String drinkType) {
       this.drinkType = drinkType;
   }
  
  
   @Override
   public int getBasePricePerOz() {
       // TODO Auto-generated method stub
       return super.getBasePricePerOz();
   }
  
   @Override
   public int getDrinkSize() {
       // TODO Auto-generated method stub
       return super.getDrinkSize();
   }

   @Override
   public void setBasePricePerOz(int size) {
       // TODO Set the base price according to the size of the drink

       if(size == 12) {
           this.basePricePerOz = this.basePricePerOz + 50;
       } else if(size == 16) {
           this.basePricePerOz = this.basePricePerOz + 100;
       } else {
           this.basePricePerOz = 10;
       }
   }
  
   @Override
   public void printDrinkInformation() {
       // TODO Auto-generated method stub
      
       System.out.println("Drink Type : "+this.drinkType);
      
       if(this.drinkSize == 6)
           System.out.println("Small Drink");
       else if(this.drinkSize == 12)
           System.out.println("Medium Drink");
       else if(this.drinkSize == 16)
           System.out.println("Large Drink");
      
       System.out.println("Your coffee costs :"+this.basePricePerOz+" cents");
   }
  
   @Override
   public void setDrinkSize(int drinkSize) {
       // TODO Auto-generated method stub
       this.setDrinkSize(drinkSize);
   }
  
}

NonCaffeinatedDrinks.java

package com.test.coffeeshop;

public class NonCaffeinatedDrinks extends Drinks {
  
   public int basePricePerOz;
   public int drinkSize = 6; //Initialize to small size by default
  
   @Override
   public void setBasePricePerOz(int basePricePerOz) {
       // TODO Auto-generated method stub
       this.basePricePerOz = 2 * super.basePricePerOz;
   }
}

Tea.java

package com.test.coffeeshop;

public class Tea extends CaffeinatedDrinks {
  
   public int drinkSize = 6; //Initialize to small size by default
   public String teaFlavor = "";
  
   public Tea(int size, String type) {
       super();
       this.drinkSize = size;
       this.teaFlavor = type;
   }
  
   @Override
   public void setBasePricePerOz(int size) {
       // TODO Auto-generated method stub
       super.setBasePricePerOz(size);
   }
      
   @Override
   public void printDrinkInformation() {
       // TODO Auto-generated method stub
      
   System.out.println("Tea Flavor : "+this.teaFlavor);
      
       if(this.drinkSize == 6)
           System.out.println("Small Drink");
       else if(this.drinkSize == 12)
           System.out.println("Medium Drink");
       else if(this.drinkSize == 16)
           System.out.println("Large Drink");
      
       System.out.println("Your tea costs :"+this.basePricePerOz+" cents");
   }
}

Last, the client - CoffeeShop.java

package com.test.coffeeshop;

import com.test.coffeeshop.Tea;
import com.test.coffeeshop.Coffee;


public class CoffeeShop {

   /**
   * @param args
   */
   public static void main(String[] args) {
      
       //Create a coffee
       Coffee myCoffee = new Coffee(12,"Latte");
       myCoffee.setBasePricePerOz(myCoffee.drinkSize);
       System.out.println(" ");
       myCoffee.printDrinkInformation();
      
       //Create a tea
       Tea myTea = new Tea(6, "Green");
       myTea.setBasePricePerOz(myTea.drinkSize);
       System.out.println(" ");
       myTea.printDrinkInformation();
      
       //Print total price
      
       float totalPrice = (float) (myCoffee.basePricePerOz + myTea.basePricePerOz)/100;
       System.out.println(" Your total price is: "+totalPrice+" dollars.");
   }
}

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