Write a class named blend The blend class should contain me

Write a class named blend. The blend class should contain me the quantity of the total coffee in the blend (in pounds), the time of the roast (in hours use a double) of the blend, the name of the blend, and predicted yield in gallons of the blend. Each blend may contain up to three different coffees and will contain the pounds of each used. The blend should have a constructor and applicable methods and be able to display each of the coffees used in the blend via the methods called in any instance. (You should use aggregation in this class)

Solution

Using aggregation here. hence two classes - Coffee and Blend

Coffee.java

package sample;

public class Coffee {

  

   String CoffeeName;

   double poundsOfCoffee;

  

   public String getCoffeeName() {

       return CoffeeName;

   }

   public void setCoffeeName(String coffeeName) {

       CoffeeName = coffeeName;

   }

   public double getPoundsOfCoffee() {

       return poundsOfCoffee;

   }

   public void setPoundsOfCoffee(double poundsOfCoffee) {

       this.poundsOfCoffee = poundsOfCoffee;

   }

  

}

Blend.java

package sample;

public class Blend {

  

   double quantity;

   double timeOfRoast;

   String nameOfBlend;

   double predictedYield;

   Coffee coffees[];

  

   Blend(String name, Coffee coffees[], double timeOfRoast, double predictedYield)

   {

       this.nameOfBlend = name;

       this.coffees = coffees;

       this.timeOfRoast = timeOfRoast;

       this.predictedYield = predictedYield;

       quantity = coffees[0].poundsOfCoffee + coffees[1].poundsOfCoffee + coffees[2].poundsOfCoffee;

   }

   public double getQuantity() {

       return quantity;

   }

   public void setQuantity(double quantity) {

       this.quantity = quantity;

   }

   public double getTimeOfRoast() {

       return timeOfRoast;

   }

   public void setTimeOfRoast(double timeOfRoast) {

       this.timeOfRoast = timeOfRoast;

   }

   public String getNameOfBlend() {

       return nameOfBlend;

   }

   public void setNameOfBlend(String nameOfBlend) {

       this.nameOfBlend = nameOfBlend;

   }

   public double getPredictedYield() {

       return predictedYield;

   }

   public void setPredictedYield(double predictedYield) {

       this.predictedYield = predictedYield;

   }

   public Coffee[] getCoffees() {

       return coffees;

   }

   public void setCoffees(Coffee[] coffees) {

       this.coffees = coffees;

   }

  

   public void printCoffeesUsed()

   {

       for(int i=0; i<3; i++)

       {

           System.out.println(\"Coffee Name: \" + coffees[i].CoffeeName);

           System.out.println(\"Coffee Weight: \" + coffees[i].poundsOfCoffee);

       }

   }

}

Write a class named blend. The blend class should contain me the quantity of the total coffee in the blend (in pounds), the time of the roast (in hours use a do
Write a class named blend. The blend class should contain me the quantity of the total coffee in the blend (in pounds), the time of the roast (in hours use a do
Write a class named blend. The blend class should contain me the quantity of the total coffee in the blend (in pounds), the time of the roast (in hours use a do

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site