Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will write a program that manages a database for a retail flower shop using object-oriented programming with at least three classes, where one of

You will write a program that manages a database for a retail flower shop using object-oriented programming with at least three classes, where one of them (the driver) should be called : FlowersDriver. The other two are to be called Flower and DatabaseTotals. The main method of the program will be in the class FlowersDriver and will include a loop that allows you to enter datatbase commands, one at a time, from a menu. The exact number of classes that you use is up to your design discretion, but use at least these three. Once a command is selected (selected by typing in an integer on the Console), that command will be executed and the user will be asked to selection another command indefinitley until they choose the command that terminates the program.

Program Description/Requirements:

A)

The Flower Class will contain the definition of an individual flower record that will include instance variables and accessor and mutator methods. The Flower class will contain the following:

Instance variables:

iD (5-digit integer flower ID number) name (String, for simplicity of reading, we will use only single-string names) color (String) size (String, Small, Medium, Large, Jumbo) wholesalePrice (double) retailPrice (double) onHand (integer - how many of that specific flower are in stock)

Instance methods:

The full set of accessor and mutator methods, one for each instance variable, i.e., each accessor method name will begin with 'get' and each mutator method will begin with 'put.' For example you would define getID() and putID().

Also include the following constructor that will intialize the instance variables as shown:

 image text in transcribed

Any additional methods in this class are at your design descretion but are not required.

B)

The DatabaseTotals class definition will contain the following instance variables:

// integer values.. totalFlowerNameCount (integer) totalFlowerCount (integer) totalItemsSold (integer) totalItemsAdded (integer) totalItemsPurchased (integer) totalOnHand (integer) // next the double values.. totalWholesaleValue (double) totalRetailSales (double) totalTaxesCollected (double) totalSalesProfit (double) salesTaxRate (double)

Include the following constructor method:

 image text in transcribed

Which explicitly sets everything to zero. As for the Flower class, create a full set of accessor and mutator methods, one for each instance variable, i.e., each accessor method name will begin with 'get' and each mutator method will begin with 'put.' For example you would define getTotalRetailSales() and putTotalRetailSales().

Source .txt file 'Flowers_db.txt':

image text in transcribed

copy-able text from source file:

45230 Rose Red Small 1.29 3.99 10 45231 Rose Red Medium 2.29 5.99 8 45235 Rose Pink Small 1.49 4.29 2 56123 Tulip Yellow Large 3.15 6.99 6 56129 Tulip White Jumbo 5.99 14.79 1 67801 Daffodil Yellow Medium 1.59 4.69 12 67805 Daffodil White Small 1.89 4.99 17 88900 Hyacinth Purple Medium 2.09 4.99 11 88905 Hyacinth Pink Small 1.69 3.79 21 88909 Hyacinth White Small 1.79 3.99 19 98330 Zenia Purple Medium 1.39 3.99 8 98334 Zenia Blue Small 1.39 3.99 15 98338 Zenia White Small 1.39 3.99 11 34501 Pansy Purple Medium 1.99 2.99 22 34507 Pansy Blue Large 3.19 7.99 10 22002 Lily White Large 2.99 9.99 7 22004 Lily Orange Small 1.99 4.39 14 10003 Poinsettia Red Jumbo 5.99 15.99 5 10004 Poinsettia Yellow Small 1.69 5.49 16 78781 Lupine Blue Medium 2.09 5.29 6 78787 Lupine Pink Small 1.49 3.29 18 46780 Penstemon Pink Medium 2.09 5.19 9 54902 Daisy Yellow Large 1.79 4.29 12 54906 Daisy Purple Small 1.39 3.99 20 35701 Poppy Orange Small 0.99 2.09 32 35701 Poppy Red Jumbo 2.19 6.09 8 20802 Iris White Medium 2.69 5.59 14 20804 Iris Red Small 2.79 6.09 19 20804 Iris Blue Medium 3.19 7.69 11 14564 Sunflower Yellow Large 2.09 5.79 6 17200 Bluebell Blue Small 0.89 2.89 16 94562 Gilia Red Medium 1.49 2.89 9 83453 Begonia Pink Jumbo 4.19 16.99 4 83454 Begonia White Jumbo 4.19 16.99 3 67121 Dahlia Yellow Medium 1.89 3.99 10 67125 Dahlia Orange Small 1.09 2.99 17 55601 Lilac Purple Large 4.99 11.99 8 55604 Lilac White Jumbo 12.99 25.99 2 44227 Gladiola Pink Large 3.59 10.99 11 44231 Gladiola Orange Small 1.49 4.59 20 91230 Snapdragon Purple Large 4.59 11.79 6 91235 Snapdragon Blue Medium 3.29 7.99 15 77245 Geranium Blue Small 2.39 8.59 7 77246 Geranium Pink Jumbo 4.79 13.49 2 05670 Veronica Purple Small 4.29 9.98 14 05673 Veronica White Medium 5.79 13.49 6 22222 Violet Purple Small 1.29 3.89 26 22223 Violet Pink Large 1.99 5.29 13 0 0 0 0 0 0 0.0 0.0 0.0 0.0 0.08

Here is the list of actions the FlowersDriver needs to take:

1)

Create an array of Flower objects to hold the contents of the flower database for processing. We will limit the number of elements of this array to 50 elements, so use the following in the appropriate place in the Flower class definintion to set that up.

public static final int MAX_FLOWERS_COUNT = 50;

2)

Read Flowers_db and fill your flowers array with the contents of the individual flower records and also, based on the data for the entire flowers database stored in the flowers array, update the totals values into the instance variables found in a DatabaseTotals object you create. For example, this would include adding up all of the wholesale prices values to get the total of the entire collection.

3)

In order to make a database for efficient for processsing, it is advantageous to sort the flower records alphabetically by name. So, at this point you need to do that. Note that the original file already has the flowers grouped by name (but other characteristics can vary for each individual flower of a given name, i.e., there can be several with the name 'Rose' but they can be different colors and sizes). You should create another array of Flower obejcts the same length as the original flower array and fill it with an alphabetically sorted version. Use as a resource the Sorting of an Array code that is found on p. 388 of Savitch 6th ed.; pattern your sort algorithm on that code, which is a selection sort. Because we have potentially multiple flowers of the same name, the sorting for this will not be quite as simple as the SelectionSort class example; however, most of this example can be used to guide your own sorting. Once the sorting is completed, you will write the contents of the sorted flowers array into a new text file called alphaFlowers_db.txt. In addition to the sorted list of individual flower records, you need to write the 0 for marking the end of those and then write to the file the totals values.

So, as an example, the alphaFlowers_db.txt file should look like the following:

image text in transcribed

4)

Once the database has been successfully sorted, you can now set up the command menu and have it execute commands that do something with the database; however, you are only required to write three commands that execute. You program will present the user with the following menu:

image text in transcribed

You are to get this menu running within a loop that will continue to run, asking for the command, until the user types a '0' to terminate the program. You are only required to implement 1), 2), and 6). For the rest all you need to do is output a message, for example:

" - Buy New Flower"

outputOneFlower() will be the simplest of the three. You simply get the flowerID as input from the Console and then print out to the Console the contents of the flower record for the flower that matches that flowerID number. If you type in a non-existing flower number, then output an error message and ask and transfer control back to the command menu.

Once the user chooses to quit the program by typing '0,' then update alphaFlower_db.txt to reflect whatever changes you have made in the database content. This will include updating the totals values as well.

Demontrate the action of the three commands, by outputting the updated database contents to the Console and submitting the latest alphaFlower_db.txt file.

// no argument constructor to set everything to zero except the iD.. public Flower() { iD = 1; name color size retailPrice = 0.0; wholesalePrice = 0.0; onHand = = } // end no argument constructor Flower().. public Database Totals() { // initialize instance variables.. totalFlowerNameCount = 0; totalFlowerCount = 0; totalItems Sold = 0; totalItemsAdded = @; totalonHand = 0; // next the double values.. totalWholesaleValue = 0.0; totalRetailSales = 0.; totalTaxesCollected = 0.0; totalsalesProfit = 0.0; salesTaxRate = 0.00; } // end Database Totals Constructor.. 45230 Rose Red Small 1.29 3.99 10 45231 Rose Red Medium 2.29 5.99 8 45235 Rose Pink Small 1.49 4.29 2 56123 Tulip Yellow Large 3.15 6.99 6 56129 Tulip White Jumbo 5.99 14.79 1 67801 Daffodil Yellow Medium 1.59 4.69 12 67805 Daffodil White Small 1.89 4.99 17 88900 Hyacinth Purple Medium 2.09 4.99 11 88905 Hyacinth Pink Small 1.69 3.79 21 88909 Hyacinth White Small 1.79 3.99 19 99330 Zenia Purple Medium 1.39 3.99 8 98334 Zenia Blue Small 1.39 3.99 15 98338 Zenia White Small 1.39 3.99 11 34501 Pansy Purple Medium 1.99 2.99 22 34507 Pansy Blue Large 3.19 7.99 10 22002 Lily White Large 2.99 9.99 7 22004 Lily Orange Small 1.99 4.39 14 10003 Poinsettia Red Jumbo 5.99 15.99 5 10004 Poinsettia Yellow Small 1.69 5.49 16 78781 Lupine Blue Medium 2.09 5.29 6 78797 Lupine Pink Small 1.49 3.29 19 46780 Penstemon Pink Medium 2.09 5.19 9 54902 Daisy Yellow Large 1.79 4.29 12 54906 Daisy Purple Small 1.39 3.99 20 35701 Poppy Orange Small 0.99 2.09 32 35701 Poppy Red Jumbo 2.19 6.09 8 20802 Iris White Medium 2.69 5.59 14 20804 Iris Red Small 2.79 6.09 19 20804 Iris Blue Medium 3.19 7.69 11 14564 Sunflower Yellow Large 2.09 5.79 6 17200 Bluebell Blue Small 0.89 2.89 16 94562 Gilia Red Medium 1.49 2.899 83453 Begonia Pink Jumbo 4.19 16.994 83454 Begonia White Jumbo 4.19 16.99 3 67121 Dahlia Yellow Medium 1.89 3.99 10 67125 Dahlia Orange Small 1.09 2.99 17 55601 Lilac Purple Large 4.99 11.99 8 55604 Lilac White Jumbo 12.99 25.99 2 44227 Gladiola Pink Large 3.59 10.99 11 44231 Gladiola Orange Small 1.49 4.59 20 91230 Snapdragon Purple Large 4.59 11.79 6 91235 Snapdragon Blue Medium 3.29 7.99 15 77245 Geranium Blue Small 2.39 8.59 7 77246 Geranium Pink Jumbo 4.79 13.49 2 05670 Veronica Purple Small 4.29 9.99 14 05673 Veronica White Medium 5.79 13.49 6 22222 Violet Purple Small 1.29 3.89 26 22223 Violet Pink Large 1.99 5.29 13 0 00000 0.0 0.0 0.0 0.0 0.08 83453 Begonia Pink Jumbo 4.19 16.99 4 83454 Begonia White Jumbo 4.19 16.99 3 17200 Bluebell Blue Small 0.89 2.89 16 67801 Daffodil Yellow Medium 1.59 4.69 12 67805 Daffodil White Small 1.89 4.99 17 67121 Dahlia Yellow Medium 1.89 3.99 10 and more flower records... 24 48 0 559 3093.67 1213.47 0.00 0.00 0.08 Select a menu item: 1) Delete Flower 2) Add Flower 3) Sell Flower 4) Buy New Flower 5) Buy More of Existing Flower 6) Look Up Flower a) Quit with a goodbye message

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

Students also viewed these Databases questions

Question

Explain the getline ( ) What does it do and why would you use it ?

Answered: 1 week ago

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago