Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java Create and test a FlowerCounter class: Write a program in a class FlowerCounter that computes the cost of flowers sold at a flower

In Java

Create and test a FlowerCounter class:

Write a program in a class FlowerCounter that computes the cost of flowers sold at a flower stand.

There are 5 kinds of flowers, petunia, pansy, rose, violet, and carnation, which cost, respectively, 50, 75, $1.50, 50, and 80 per flower.

Create an array of Strings that holds the names of these flowers. Create another array that holds the cost of each corresponding flower. Hints: you can use the Java array initializer syntax to create these; make sure the indexes of each flowers name and cost are the same.

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 name array and use that same index to obtain the cost per flower from the cost array. 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: use the Scanner next() method to read in the name of the flower, or else use Keyboard.next(); if the user did not type quit in lower or upper case, use equalToIgnoreCase() in a loop to 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 name array, and if so print a message saying the shop does not sell that kind of flower.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions