Assignment 11

Due Tuesday, February 20 at 11:20am on Canvas



Assignment 11.1: 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 project called Planet.
  • 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.


Assignment 11.2: Hickory-Dickory-Dock (10 pts)
  • Create a new Java file called Hickory.java.
  • Write a program that uses a while loop to print the numbers from 1 to 150, with each number printed on its own line.
  • For multiples of three print "Hickory!" instead of the number
  • For the multiples of five print "Dickory!" instead of the number.
  • For numbers which are multiples of both three and five print "Dock! The Mouse Ran Up the Clock!".
  • You must use a while loop for full credit.
  • Hint: Test for numbers that are multiples of both 3 and 5 first.
  • When you are finished, and your output looks like mine, upload your assignment to Canvas.
Your Output Should Look Like the Following. Note that some values have been omitted for brevity.

1
2
Hickory!
4
Dickory!
Hickory!
7
8
Hickory!
Dickory!
11
Hickory!
13
14
Dock! The Mouse Ran Up the Clock!
16
17
Hickory!
19
Dickory!
Hickory!
22
...
149
Dock! The Mouse Ran Up the Clock!