Question

Write a class named blend. The blend class should contain me the quantity of the total...

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)

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

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);

       }

   }

}

Add a comment
Know the answer?
Add Answer to:
Write a class named blend. The blend class should contain me the quantity of the total...
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
  • Create a class named Pizza that scores information about a single pizza. It should contain the...

    Create a class named Pizza that scores information about a single pizza. It should contain the following:  Private instance variable to store the size of the pizza (either small, medium, or larger), the number of cheese toppings, the number of pepperoni toppings, and the number of ham toppings.  Constructor(s) that set all of the instance variables.  Public methods to get and set the instance variables.  A public method named calsCost( ) that returns a double that...

  • In C++ Write a program that contains a class called VideoGame. The class should contain the...

    In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....

  • Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default...

    Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • Please use C++. Write a class named Circle that has a double data member named radius...

    Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....

  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

  • Task 1: 1. Write a generic class named MyList, with a type parameter T. The type...

    Task 1: 1. Write a generic class named MyList, with a type parameter T. The type parameter T should be constrained to an upper bound: the Number class. The class should have as a field an ArrayList of type T. Write the class constructor to create the ArrayList. 2. Write a public method named add, which accepts a parameter of type T. When an argument is passed to the method, add it to the ArrayList. 3. Write a public method...

  • q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have...

    q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have a public constructor that takes a JTextArea and a JLabel as parameters and stores these in instance variables. Override the mouseEntered method to . display the text from the JTextArea on the JLabel in all upper case letters. Then, override the mouseReleased method to display the text from the JTextArea on the JLabel in all lower case letters. The other three methods from the...

  • Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class...

    Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class should have a constructor and appropriate accessor and mutator methods. Thenwrite a program that creates at least five PhoneBookEntry objects and stores them in anArrayLitt. Use a loop to display the contents of each object in the ArrayList.

  • Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double...

    Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double variable that holds the rooms length(in feet). Breadth: The double variable that holds the rooms breadth(in feet). Height: Double variable that holds rooms height in feet. Color: String object that holds the color you want the room to be painted with. The class should have a constructor to initialize the fields for a particular instance (or object) of the class as given: All double...

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