Programming Project: Four Java Programs

1) Wholesale Price You happen to know that a store has a 25% markup on compact-disc (CD) players. If the retail price (what you pay) of a CD player is $189.98, how much did the store pay for that item. In other words, what is the wholesale price? Write a Java program in a file named WholesalePrice.java that can compute the wholesale price for any item given its retail price and markup. Your dialog must look like this beginning with a brief explanation of what the program does:

This program determines what a retailer pays for something
given the retail price and the markup (100 represents 100%).

Enter the retail price: 255.00

Enter the markup percentage as a whole number [0..400]: 50

Wholesale price = 170.0

Notes:

·  Retail price = wholesale price * (1 + markup)

2) Gasoline Measurements. Write a Java program in the file Gas.java that prompts the user for a floating point number which stands for gallons of gasoline. You will reprint that value along with other information about gasoline and gasoline usage (thanks to Richard Enbody, Michigan State):

·  Number of liters

·  Number of barrels of oil required

·  Number of pounds of CO2 produced

·  Equivalent energy amount of ethanol gallons

·  Price in US dollars

You can find these measures on the web (try wikipedia), but just in case:

·  1 gallon is equivalent to 3.7854 liters

·  1 barrel of oil produces 19.5 gallons of gas (approximately, can vary depending on the oil source. This number will work for us). FYI, a barrel is 42 gallons.

·  1 gallon of gas produces approximately 20 pounds of CO2. Again, good enough

·  1 gallon of gas produces 115,000 BTU (British Thermal Units). 1 gallon of ethanol produces 75,700 BTU.

·  Who knows what the cost should be, but let’s state it at $3.67/gallon

You design your dialog that must contain the prompt and the five conversions listed above.

3) MinimumCoins Shoprite Groceries wants to save time at the checkout registers. To do so, Shoprite figures it would help to have a machine to automatically dispense the coin change. To save coins and save time, they would like to have the minimum number of coins dispersed. To work out the code to determine the minimum number of coins, write a Java program named MinimumCoins.java that prompts for an integer that represents the amount of change (in cents) to be handed back to a customer in the United States. Display the minimum number of half dollars, quarters, dimes, nickels, and pennies that make the correct change. Verify that your program works correctly by running it with a variety of input. Assume we will always use valid input, integers from 0..99. Your dialog must look like this beginning with a brief explanation of what the program does:

This program determines the minimum coins

needed to make from 0 to 99 cents change.

Enter change [0..99]: 83

Half(ves) : 1

Quarter(s): 1

Dime(s): 0

Nickel(s): 1

Penny(ies): 3

4) Einstein Number It is said that Albert Einstein used to take great delight in baffling friends with the puzzle below. First, write the number 1089 on a piece of paper, fold it, and hand it to a friend for safekeeping. What you wrote down is not to be read until you have completed your amazing mental feat. Next, ask your friend to write down any three-digit number, emphasizing that the first and last digits must be different. Close your eyes or turn your back while this is being done. Better still, have someone blindfold you.


After your friend has written down the three-digit number, ask your friend to reverse it and then to subtract the smaller from the larger. Example: 654 - 456 = 198. Once this is done, tell your friend to reverse the new number. Example: 198 becomes 891. Next ask your friend to add the new number and its reverse together. Example: 198 + 891 = 1089. If all goes as planned, your friend will be amazed. The number you wrote down at the start, 1089, will always be the same as the end result of this mathematical trick. To simulate this baffle, write a program in a file named EinsteinNumber.java that reads a three digit number and prints all the steps. Your dialog must look like this beginning with a brief explanation of what the program does when the user enter 541:

This program shows the steps involved in the

baffling number game from Albert Einstein.

Enter a 3 digit number where the 1st and 3rd digits are different: 541

541 -- original

145 -- reversed

396 -- difference

693 -- reverse of the difference

1089 -- the difference + reverse of the difference

Notes

·  You don’t need to error check the three digit number. Assume input is in the range of 100 to 998 where the first and third digits are never the same. No 101 or 252 or 989 for example.

·  541 % 10 is 1

·  541 / 100 is 5

·  Math.max(a, b) returns the larger of a and b

·  Math.min(a, b) returns the smaller of a and b

·  Math.abs(a - b) returns the positive difference between a and b even if b is bigger

Grading Criteria 100 pts (Subject to Change) Submit to D2L Dropbox "Four Projects"

Each of the four programs are worth 25 points each:

1 pts Your code compiles and attempts to solve the problem

1 pts You have your name in a comment at the top of the program
2 pts Your programs are named as specified

3 pts Your dialogs match exactly as requested or very close (subjective) or clear in Gas.java

3 pts You used meaningful names for all identifiers (subjective)

15 pts Your program is correct. It always works for valid input (no bad input allowed)