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 |
To write a computer program that prints out the weight of a person on the Moon, Mars, and Jupiter
- A working Java environment
- printf
- The masses of Jupiter, Mars, the Moon, and the weight of few friends on Earth
- Knowledge of Java primitive data types
- Basic knowledge of using Java operators on primitive data types
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
Body | Earth Mass ratio |
---|---|
Earth | 1 |
the Moon | 0.16 |
Mars | 0.37 |
Jupiter | 2.364 |
//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!
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.
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!
The following url was used to get the Earth mass ratios for various bodies: http://www.seasky.org/solar-system/planet-weight-calculator.html