Question: 13.2: Healthy Nuts (Java eclipse) Encoding and decoding information can save memory space and speed transmission of data. Businesses often encode orders to reduce writing

13.2: Healthy Nuts (Java eclipse)

  • Encoding and decoding information can save memory space and speed transmission of data.
  • Businesses often encode orders to reduce writing and speed up customer orders. In this project we will look at decoding orders for a nut company.
  • Nuts are a healthy snack. The Global Burden of Disease Study [1] calculated that eating more nuts could save 2.5 million lives each year.
  • From another perspective, your life span may be increased by two years by eating nuts regularly [2].
  • Write a program (Nuts.java) that prompts the user for a single input where the first one or two characters is a nut in the following shorthand code and the last characters are the number of ounces for the nut type.

image source

Code Nut Variety
A Almonds
BN Brazil Nuts
C Cashews
HN Hazelnuts
M Macadamias
P Peanuts
PE Pecans
PN Pine Nuts
PI Pistachios
W Walnuts
  • For example, the code for twelve ounces of Brazil Nuts is BN12 and seven ounces of Cashews is C7.
  • Notice there are no spaces between the code and quantity.
  • The quantity can be any amount greater than or equal to zero.Ask the user for the following inputs (and no other input) in this order, as shown in the example output below:
  • A single order code like: BN12 (no spaces allowed!!)
  • A 'y' or 'n' (without the quotes) for the repeat loop
  • Assume the user enters all the codes with UPPERCASE letters as shown.
  • Store the order code in a single String variable.
  • Then use substring() to analyze and process the input String to print a full description of the nut order.
  • Add a while statement that allows the user to repeat the program by entering a 'y' (without the quotes)
  • If the user enters an invalid code, display the message, "We don't have that nut." as shown in the example output.
  • Submit Nuts.java to Canvas when you are finished.

The output of your program should look identical to the sample output below except user input may vary.:

Welcome to the Health Nut Company!

Enter the nut order code: BN12

12 oz. Brazil Nuts

Another item? (y) y

Enter the nut order code: C7

7 oz. Cashews

Another item? (y) Y

Enter the nut order code: XY123

We don't have that nut.

Another item? (y) n

We will go nuts to get you this order!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!