Question: In Java, create and test a Flower and Florist class that work together using objects and arrays: Write a Flower class with two instance variables:
In Java, create and test a Flower and Florist class that work together using objects and arrays:
Write a Flower class with two instance variables: String name and double cost. Flower has a single constructor that takes a String and a double parameter and sets the instance variables from them. Flower also has getter methods for both instance variables, but does not have any setter methods. Finally, Flower has a public String toString() method that returns a String containing the name of the flower and its cost.
Copy the FlowerCounter program as the base for a class Florist that computes the cost of flowers sold at a flower stand.
As in FlowerCounter there are 5 kinds of flowers, petunia, pansy, rose, violet, and carnation, which cost, respectively, 50, 75, $1.50, 50, and 80 per flower.
Florist creates an array flowers of Flower objects containing this information; use 5 assignment statements to create the objects. Then Florist should print those objects in a for or for-each loop.
Your program should read the name of a flower and the quantity (number of flowers) desired by a customer in a loop; when the user types quit, exit the loop. Locate the flower in the flowers array using each Flower objects getName() method, and use that objects getCost() method to obtain the cost per flower. At the end, print the number of flowers bought and the total cost of the sale (you have to accumulate this information in the loop).
Hints: if the user did not type quit, compare their flowers name against those in the array be sure to deal with the case where the user wants to buy a flower whose name doesnt exist in the flowers array, and if so print the same message as above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
