Question

In: Computer Science

Use menu based functionality and validation loops to create a new customer bonus fruit package application...

Use menu based functionality and validation loops to create a new customer bonus fruit package application for the Dirt to Dish discount produce company.

The program you create will prompt the user to enter a number to select one of three bonus pack options:

1 for Apple pack
2 for Orange pack
3 for Banana pack


**Use input validation to ensure a valid option has been selected before proceeding.

Use variables to keep track of how many of each fruit a customer will have depending on which bonus pack has been chosen. The amount of fruit per bonus pack is given as follows:

Banana pack: 5 bananas, 2 apples, 2 oranges
Orange pack: 5 oranges, 2 apples, 2 bananas
Apple pack: 5 apples, 2 bananas, 2 oranges

Use menu based functionality and input validation and prompt the user to choose from one of the following recipes:

1. Fruit medley (2 of each fruit)
2. Mixed Apple Pie (3 apples, 1 orange, 1 banana)
3. Banana tower (4 bananas, 2 oranges)
The amount of fruit required for each recipe is shown in parenthesis.

After a valid recipe choice has been made, subtract the amount of fruit needed for the recipe if the customer has enough fruit. If the customer does not have enough fruit then show a message telling the customer to buy more fruits.

Finally display the amount of fruit remaining from the bonus pack after the recipe selection has been made.

First example run:

This is Dirt to Dish's new customer bonus service!
Please select your free fruit package:
1. Apple pack
2. Orange pack
3. Banana pack
Please enter 1, 2, or 3: 2
You have chosen: Orange pack

You have a total of:
2 apples 5 oranges 2 bananas
Which dish would you like to make first?
1. Fruit medley (2 of each fruit)
2. Mixed Apple Pie (3apples, 1 orange, 1 banana
3. Banana tower (4 bananas, 2 oranges
Please enter 1, 2, or 3: 2
Mixed Apple Pie chosen
Sorry, you need more fruits!
The fruit you have left is:
2 apples
5 oranges
2 bananas

Thank you!

Solutions

Expert Solution

'''

Python version : 2.7

Python program to create a new customer bonus fruit package application

for the Dirt to Dish discount produce company.

'''

def main():

               # variables to store the number of apples, oranges and bananas

               numApples = 0

               numOranges = 0

               numBananas = 0

              

               print("This is Dirt to Dish's new customer bonus service!")

               # input of pack choice

               print('Please select your free fruit package:')

               print('1. Apple pack')

               print('2. Orange pack')

               print('3. Banana pack')

               packChoice = int(raw_input('Please enter 1, 2, or 3:'))

              

               # validate the pack choice and re-prompt in case of invalid values

               while(packChoice < 1 or packChoice > 3):

                              print('Invalid choice.')

                              packChoice = int(raw_input('Please enter 1, 2, or 3:'))

              

               # set the number of apples, oranges and bananas based on the pack choice

               if packChoice == 1:

                              print('You have chosen: Apple pack')

                              numApples = 5

                              numBananas = 2

                              numOranges = 2

               elif packChoice == 2:

                              print('You have chosen: Orange pack')

                              numApples = 2

                              numOranges = 5

                              numBananas = 2

               else:

                              print('You have chosen: Banana pack')

                              numApples = 2

                              numOranges = 2

                              numBananas = 5

              

               print('\nYou have a total of:')

               print('%d apples %d oranges %d bananas' %(numApples,numOranges,numBananas))

               # input of dish choice

               print('Which dish would you like to make first?')

               print('1. Fruit medley (2 of each fruit)')

               print('2. Mixed Apple Pie (3apples, 1 orange, 1 banana)')

               print('3. Banana tower (4 bananas, 2 oranges)')

               dishChoice = int(raw_input('Please enter 1, 2, or 3: '))

              

               # validate the dish choice and re-prompt in case of invalid values

               while(dishChoice < 1 or dishChoice > 3):

                              print('Invalid choice.')

                              dishChoice = int(raw_input('Please enter 1, 2, or 3:'))

              

               enoughFruits = True

               # check if enough fruits are available to create the dish and calculate the number of remaining fruits after creating the dish

               if dishChoice == 1:

                              print('Fruit medley chosen')

                              enoughFruits = (numApples >= 2 and numBananas >=2 and numOranges >=2)

                              if enoughFruits :

                                             numApples -= 2

                                             numBananas -= 2

                                             numOranges -= 2

                                            

               elif dishChoice == 2:

                              print('Mixed Apple Pie chosen')

                              enoughFruits = (numApples >=3 and numOranges >=1 and numBananas >=1)

                              if enoughFruits :

                                             numApples -= 3

                                             numBananas -= 1

                                             numOranges -= 1

               else:

                              print('Banana tower chosen')

                              enoughFruits = (numBananas >=4 and numOranges >=2)

                              if enoughFruits :

                                             numBananas -= 4

                                             numOranges -= 2

              

               # if not enough fruits available, then print the message

               if not enoughFruits:

                              print('Sorry, you need more fruits!')

               # print the remaining fruits

               print('The fruit you have left is:')

              

               # only print those fruits that are remaining, not print 0 valued fruits

               if numApples > 0:

                              print('%d apples' %(numApples))

              

               if numOranges > 0:

                              print('%d oranges '%(numOranges))

              

               if numBananas > 0:

                              print('%d bananas' %(numBananas))

               print('\nThank you!')       

# call the main function

main()   

#end of program

Code Screenshot:

Output:


Related Solutions

Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER...
Use C++ to create an application that provide the menu with two options TemperatureConverter_Smith.cpp MENU CONVERTER TEMPERATURE – JAMES SMITH Convert Fahrenheit temperature to Celsius Convert Celsius temperature to Fahrenheit Exit CASE 1: Convert Fahrenheit temperature to Celsius -Display the message to ask to enter Fahrenheit degree from the keyboard -Use the following formula to convert to Celsius degree         Celsius Temperature = (Fahrenheit Temperature – 32) * 5/9 ; -Display the output as below: TemperatureConverter_Smith.cpp TEMPERATURE CONVERTER – JAMES...
Using Ruby Your extended Text Based Music Application must add the following functionality: Display a menu...
Using Ruby Your extended Text Based Music Application must add the following functionality: Display a menu that offers the user the following options: 1. Read in Albums 2. Display Albums 3. Select an Album to play 4. Update an existing Album 5. Exit the application Menu option 1 should prompt the user to enter a filename of a file that contains the following information: ·The number of albums ·The first album name ·The first artist name ·The genre of the...
Create a Java application NumberLoops to practice loops. The draft has one loop to calculate a...
Create a Java application NumberLoops to practice loops. The draft has one loop to calculate a product and the final will add another loop to print integers in a required format. There is no starter code for the problem. Use a Scanner to input an integer then compute and display the product of all positive integers that are less than the input number and multiple of 3. If no numbers satisfy the conditions, then print out 1 for the product....
We need a Stock and Bond trading application. Here is what is required: Create Menu with...
We need a Stock and Bond trading application. Here is what is required: Create Menu with the options organized as below: ******************************************************************************** A. Buy Bonds B. Sell Bonds C. Buy Stocks D. Sell Stocks E. Short Stock Sale    X. Exit Here are the steps involved. Create a char variable named menuChoice. Display the menu as described above. Prompt for the menu choice (A-E,X) (Assume the input will be uppercased). Use an IF statement to validate that the choices are...
Create a menu-based program that will allow the user to calculate the area for a few...
Create a menu-based program that will allow the user to calculate the area for a few different shapes: square, rectangle, parallelogram, and circle. Refer to the Sample Output in this document to see what menu options you should use. Create PI as a global constant variable. Main Function use do-while to repeat program until user chooses option 5 call the displayMenu function get user choice & validate with while loop depending on user’s choice, get the data required to calculate...
Create a menu-based program that will allow the user to calculate the area for a few...
Create a menu-based program that will allow the user to calculate the area for a few different shapes: square, rectangle, parallelogram, and circle. Refer to the Sample Output in this document to see what menu options you should use. Create PI as a global constant variable. Main Function use do-while to repeat program until user chooses option 5 call the displayMenu function get user choice & validate with while loop depending on user’s choice, get the data required to calculate...
Based on Movie package example, you will create a package about your favorite TV series and...
Based on Movie package example, you will create a package about your favorite TV series and provide the plot() Readme.txt: Explain how you apply polymorphism in your program package Movie; public class MovieTester { public static void main(String[] args) { for(int i = 1; i < 11; i++){ Movie movie = randomMovie(); System.out.println("Movie # " + i + ": " + movie.getTitle() + ", Genre: " + movie.getGenre() + '\n' +"Plot: " + movie.plot()); } } public static Movie randomMovie(){...
C++ Linkedlist Create a food menu so the customer can see what we are selling, if...
C++ Linkedlist Create a food menu so the customer can see what we are selling, if the users place order that not on the menu, prompt the users to enter again. Food code and food must be matched when users enter.
Typically, McDonald’s produces menu items in advance of customer orders based on anticipated demand. In contrast,...
Typically, McDonald’s produces menu items in advance of customer orders based on anticipated demand. In contrast, Burger King produces menu items only in re- sponse to customer orders. Which system (MRP-II or lean manufacturing) does each company use? What are the relative advantages and disadvantages of each system?
Create a lottery game application. Include a menu that allows the user to play more than once, or quit after a game. You can either use dialog boxes or text based, up to you.
FOR JAVA:Summary:Create a lottery game application. Include a menu that allows the user to play more than once, or quit after a game. You can either use dialog boxes or text based, up to you.The solution file should be named Lottery.javaGenerate four random numbers, each between 0 and 9 (inclusive).Allow the user to guess four numbers.Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess, the randomly determined four-digit number,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT