Assignment 11

Due Thursday, May 17 at 1:20pm 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.1: What's Your Sign? (10 pts)


Venice ast sm.jpg

  • For this assignment, let's write an astrology program.
  • Welcome the user (see sample output below)
  • Prompt the user to enter a numerical value (1-12) for the month of his/her birth (see sample output)
  • Prompt the user to enter a numerical value (1-31) for the day of his/her birth (see sample output)
  • Then, determine the user's sign based on their input.
        Aries                March 21-April 19
        Taurus             April 20-May 20
        Gemini            May 21 - June 21
        Cancer            June 22 - July 22
        Leo                  July 23 - August 2
        Virgo                August 23 - September 22
        Libra                September 23 - October 22
        Scorpio            October 23 - November 21
        Sagittarius       November 22 - December 21
        Capricorn        December 22 - January 19
        Aquarius         January 20 - February 18
        Pisces            February 19 - March 20

  • Expect to need to use if, else if and else statements.
  • Expect to use logical operators (&&, ||).
  • Submit your source code in a file called Sign.java to Canvas when finished

Your sample output must be identical to mine:

What's your sign?
Please enter the month of your birth (1-12): 3
Please enter the day of your birth (1-31): 3
Your Sign is Pisces.


Alternately,


What's your sign?
Please enter the month of your birth (1-12): 4
Please enter the day of your birth (1-31): 12
Your Sign is Aires.


Alternately,


What's your sign?
Please enter the month of your birth (1-12): 100
Please enter the day of your birth (1-31): -2
Invalid Entry. Please run the program to try again.