Assignment 10

Due Thursday, February 14 at 11:20am on Canvas


Assignment 10.1: Making a Receipt (10 pts)

  • Let's write a program to create a receipt.
  • Open a new class called Cookies.java.
  • This program will simulate an online cookie business and print out a receipt to the customer for their order.
  • The program should follow the exact formatting shown below, including spacing and indentation.
    • Hint: Remember "\t"?
  • Note that you will need to print out exactly 2 decimal places for the dollar values.
  • When you are finished, submit your program.


    Welcome to Java Cookies!
    Allow me to assist you with your order.

    We sell the following flavors:
    Mocha Cookies -- $1.95 each
    Cocoa Cookies -- $2.15 each
    Coffee Chai Cookies -- $2.05 each
    Java Cookies (Chocolate Chocolate Chip with Macadamia) -- $1.85 each

    Please enter the number of Mocha Cookies: 3
    Please enter the number of Cocoa Cookies: 2
    Please enter the number of Coffee Chai Cookies: 5
    Please enter the number of Java Cookies: 1

    You Ordered the Following:
    Mocha Cookies: 3 @ $1.95 each...            $5.85
    Cocoa Cookies: 2 @ $2.15 each...            $4.30
    Coffee Chai Cookies: 5 @ $2.05 each...      $10.25
    Java Cookies: 1 @ $1.85 each...             $1.85

    Total:                                      $22.25

    Thank you for your order! Please come again!


Assignment 10.2: Days in a Month (10 pts)
  • Develop a program that first asks the user to enter a month (January, February, and so on) and then prints the number of days in the month followed by the word "days". For February, print the phrase "28 or 29 days".
  • The user should be able to enter upper or lower case letters for the days of the month and the program should still recognize the entry month.
  • Submit MonthDays.java when finished your output is identical to what is shown below.
Sample Output:

I will print the number of days in a month.
Enter the month (January - December): September
30 days

Alternately:

I will print the number of days in a month.
Enter the month
(January - December): february
28 or 29 days


Alternately:

I will print the number of days in a month.
Enter the month
(January - December): JaNuAry
31 days

Hint: Thirty days hath September


Assignment 10.3: Weight in Space (10 pts)
  • Remember our class activity where we calculated a user's weight on the moon?
  • Let's see if we can expand it to provide more options for the user.
    • Instead, we will calculate how the user's weight changes on different planets.
  • Working by yourself, create a Java file called Planet.java.
  • Our assignment will make use of many of the skills we have already learned:
    • Switch statements
    • Logical Operators
    • Strings and String comparison
    • Arithmetic operators and expressions
  • Begin your program by declaring a double variable named weight, and a String variable named planet.
  • You will need to write a switch statement with a series of cases, like the following:

            switch(planet) {

case "Mercury":
    weight *= MERCURY_MULT; //0.38
    break;
        //rest of cases
    }
  • Your default clause gives you the opportunity to do some error checking on the user input. 
  • If the user inputs an invalid planet, you should output the message "You entered an invalid name for a planet. Please re-run the program to try again."
  • To provide the proper weight, you will need to know the conversion rate for each of the planets. The conversion is as follows:
    • Mercury - multiply by 0.38
    • Venus - multiply by 0.91
    • Mars - multiply by 0.38
    • Jupiter - multiply by 2.54
    • Saturn - multiply by 1.08
    • Uranus - multiply by 0.91
    • Neptune - multiply by 1.19
    • Pluto - multiply by 0.06
  • Note that to avoid magic numbers, you will need to declare a final variable for each of the multipliers aboveYour final variables should look like this:
final double MERCURY_MULT = 0.38;
  • Important: The output for the weight should only have one number after the decimal point. Therefore, you need to make use of System.out.printf to print out the weights rather than println
  • Your program should work identically to the following, except user input will vary:
Welcome!
What do you weigh on other planets?
Enter your weight in pounds: 123
Now, select from one of the following planets:
    Mercury
    Venus
    Mars
    Jupiter
    Saturn
    Uranus
    Neptune
    Pluto
Please enter the planet: Mercury
You weigh 46.7 lbs on Mercury
  • Alternately, your program should output the following if the user provides an invalid entry:

Welcome!
What do you weigh on other planets?
Enter your weight in pounds: 123
Now, select from one of the following planets:
    Mercury
    Venus
    Mars
    Jupiter
    Saturn
    Uranus
    Neptune
    Pluto
Please enter the planet: Marz
You entered an invalid planet name.
Please rerun the program to try again.