Write a program in a class FlowerCounter that computes the cost of each type of
ID: 3773010 • Letter: W
Question
Write a program in a class FlowerCounter that computes the cost of each type of flower sold by the dozen.
There are 7 flower types. They are "Roses", "Magnolia", "Azalea", "Star Jasmine", "Gardenia", "Zinnia", "Lily". There is a unique cost for each flower by the dozen. The Roses are the most expensive and the Lily is the least expensive. You may come up with your own prices.
Create an array of strings that holds the names of the flowers.
Create another array that holds the cost of each corresponding flower.
Your program should allow the user to select from a menu list of flowers.
Your program should ask the user "How many dozen would you like to purchase?"
Locate the flower in the name array and use that index to find the cost per dozen in the cost array.
Compute and print the total cost of sale.
This should be a full program.
Explanation / Answer
import java.util.Scanner;
/**
*
*/
/**
* @author Srinivas Palli
*
*/
public class FlowerCounter {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
String flowerTypes[] = { "Roses", "Magnolia", "Azalea", "Star Jasmine",
"Gardenia", "Zinnia", "Lily" };
double flowerCosts[] = { 60.22, 58.65, 55.65, 53.54, 50.87, 40.56,
35.21 };
double totalCost = 0.0;
System.out.println(" Flower Type Cost");
for (int i = 0; i < 7; i++) {
System.out.println((i + 1) + ". " + flowerTypes[i] + " "
+ flowerCosts[i]);
}
System.out.print("select from a menu list of flowers:");
int ch = scanner.nextInt();
System.out.print("How many dozen would you like to purchase?");
int noOfDozens = scanner.nextInt();
totalCost = flowerCosts[ch - 1] * noOfDozens;
System.out.println("total cost of sale $" + totalCost);
}
}
OUTPUT:
Flower Type Cost
1. Roses 60.22
2. Magnolia 58.65
3. Azalea 55.65
4. Star Jasmine 53.54
5. Gardenia 50.87
6. Zinnia 40.56
7. Lily 35.21
select from a menu list of flowers:1
How many dozen would you like to purchase?2
total cost of sale $120.44
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.