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

Write a program in a class FlowerCounter that computes the cost of flowers sold

ID: 3625391 • Letter: W

Question

Write a program in a class FlowerCounter that computes the cost of flowers sold at a flower stand.Five kinds of flowers-petunia, pansy,rose,violer,and carnation-are stocked and cost,respectively, 50center,75,$1.50,50center, and 80center per flower.Create an array of strings that holds the names of these flowers.create amother array that holds the cost of each corresponding flower.Your program should read the name of flower and the quantity desired by a customer.Locate the flower in the name array and use that index to dind the cost per stem in the cost array.Compute and print the total cot of the sale.

Explanation / Answer

please rate - thanks

import java.util.*;   
public class FlowerCounter
{public static void main(String[] args)
{String types[]={"petunia","pansy","rose","violet","carnation" };
double cost[]={.5,.75,1.5,.5,.8};
double total=0;
boolean found;
int amt,i;
Scanner in=new Scanner(System.in);
String type;
System.out.print("What type of flower would you like? ");
type=in.nextLine();
do
{found=false;
for(i=0;i<types.length;i++)
      if(type.compareToIgnoreCase(types[i])==0)
            {found=true;
            System.out.print("How many "+type+"s would you like? ");
            amt=in.nextInt();
            in.nextLine(); //ignore enter
            total+=amt*cost[i];
            i=types.length; //force exit of loop
            }
        if(!found)
           System.out.println("Sorry I don't have any "+type+"s");
System.out.print("What type of flower would you like(done to exit)? ");
type=in.nextLine();
}while(type.compareToIgnoreCase("Done")!=0);
System.out.printf("Total cost of flowers: $%.2f ",total);
}
}

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