Skip to content

Latest commit

 

History

History
145 lines (138 loc) · 4.49 KB

variables.md

File metadata and controls

145 lines (138 loc) · 4.49 KB

Variables, Literals, and Constants

Skill Value
Reading User Input +3 Levels
Using Operators +1 Level
Using Primitive Variable Types +3 Levels
Formatting Console Output +3 Levels
Making Code Documentation with Markdown and Javadocs +2 Levels

Objective

To write a computer program that prints out the weight of a person on the Moon, Mars, and Jupiter

Materials

  1. A working Java environment
  2. printf
  3. The masses of Jupiter, Mars, the Moon, and the weight of few friends on Earth
  4. Knowledge of Java primitive data types
  5. Basic knowledge of using Java operators on primitive data types

Methods

Use your Java development environment to write a computer program that takes a person's name, age, and weight as input (using the Scanner class) and outputs the following pieces of information:

  • A greeting with their name inside it
  • A comment about their age
  • A formatted output showing their original weight on Earth along with their weight on the Moon, Mars, and Jupiter. Please label each weight with the planet it comes from and keep the layout and formatting nice using printf(). Make sure the names of the bodies are left-aligned and that the weights always have two decimaal places in their answer, event if the answer is a well-rounded integer. Make sure the numbers are right-aligned
  • Please write helpful comments in your code as well
  • Include a README.md file that uses markdown notation or standard html for pleasant formatting
To calculate the weight of a person on another body, all you have to do is take their original weight and multiply it by the Earth mass ratio of the other body. The answer will be that person's weight on the other planet.

Data

Body Earth Mass ratio
Earth 1
the Moon 0.16
Mars 0.37
Jupiter 2.364

Results

//SAMPLE OUTPUT

Welcome to the mass calculator, what is your name? Matt

Hi Matt! How old are you? 35

My, you're getting younger and younger! You sure are looking good for your age! Would you be so kind as to tell me your weight? (on Earth please!) 195

Let me do a bit of analysis...

All done! Here are the results:

Earth: 195.00 The Moon: 32.30 Mars: 73.50 Jupiter: 460.98

Phew! That was a work-out! Please come back again sometime!

Analysis

Please write a README.md file describing what your program is and how to use it. Talk about any difficult decisions you made about the way the program works, what it can do, and what some of its limitations or desired improvements might be. Please format your document using markdown notation or standard html.

Conclusion

Congratulations! You just learned to take input from the user, store it in variables, and use this as an approach for generalizing computer programs! You also earned some experience formatting console output with printf, commenting your code to make it easier for other programmers to read, and generating a well-formatted readme file for end-users!

References

The following url was used to get the Earth mass ratios for various bodies: http://www.seasky.org/solar-system/planet-weight-calculator.html