A02
Due Date:
Friday, September 22
File(s) to be submitted:
YearCalculator.java
Sample Output:
SampleOutput.html
SUBMIT
/
Check
Math, Input & Output
Synopsis
For this assignment,
you must create a Java application that reads a person's name
and
the year they were born,
and then produces the following output:
- A greeting, using their name.
- How old they will be at the end of this year (2023).
- About what year they can retire (at age 65).
- The average length of a generation (27.5 years).
- The approximate years their parents and grandparents were born.
- A wish for them to say "Hi" to their grandparents.
Details
This assignment is for you to practice input, output and math --
and also using proper style in your programs.
Your program starts by introducing itself.
Its introduction should include:
- a suitable title, underlined;
- a short description of the program's purpose; and
- author information -- your name and A-number.
After printing the introduction,
the program pauses, waiting for the user to press the enter key.
Hint:
How do we tell the computer to read a line of input?
Next your program does input.
It prompts for and reads the user's full name
(spaces included).
Then it prompts for and reads the year they were born.
Hint:
How many times does the user press the enter key to do that input?
After reading the user's information,
the program pauses again.
Hint:
If your program doesn't pause,
even tho' you told it to read another line,
look back at the hint for reading their name and year of birth.
There's something you forgot to do there!
Finally,
your program prints out the messages mentioned in the summary.
For example, the output might be:
Hi, Mark Young!
Since you were born in 1962, you turn 61 this year.
You will retire about 2027.
Did you know that the average generation is about 27.5 years?
That means that your parents were probably born about 1934,
and your grandparents about 1907.
Say "Hi" to your grandparents from me the next time you see them!
Further requirements:
- The length of a generation must be printed as a double.
- The years must all be printed as integers -- even the (approximate) birth years of parents & grandparents.
- Your parents were born one generation before you; your grandparents two generations before you.
- You must use variables for the current year,
the age of retirement,
and the length of a generation.
The output must still be correct
if I change the value of one of those variables.
For example,
if I change the current year variable to be 2024,
then the age should be the age the person will turn next year.
If I change the generation length to 30.0 years,
then the output should say that it's 30.0 years,
and that my parents were born about 1932,
and my grandparents about 1902 -- without any other changes to the code.
- There must be blank lines in the output separating the output into four logical chunks:
- the greeting,
- the age and retirement year,
- the generation length, parent and grandparent birth years, and
- the wish to greet their grandparents.
- And while that is all your program must do,
keep in mind that it must still satisfy the standard requirements for assignments.
In particular, that means:
- Everything has a suitable name, in the style appropriate for what it is.
- The opening/javadoc comment is present.
- The code meets the style guidelines. Which in this case means:
- Code lines are indented four spaces per level (no TABs).
- Every line is less than 80 characters long.
Commands that would go over 80 characters are broken at some suitable place,
and the continuation lines are indented eight spaces more than the first.
- Everything is spelled properly.
- Binary operators have a space on either side of them.
- Each logical chunk of code has a one-line comment saying what it does.
- The opening comment in the .java file starts with a brief description (one line is fine) of what it does.
- There must be proper prompts for the input. (The input will be echoed back in the required output.)
Grading Outline
- 5 points: uses most appropriate types for all variables
- 5 points: reads a name with two parts (e.g. Mark Young)
- 5 points: reads a name with one part (e.g. Mark) or three or more parts
(e.g. Mark Anthony Young)
- 5 points: reads a year
- 5 points: pauses after reading the year (an actual pause after the pause message)
- 5 points: reports back their full name
- 5 points: reports back their year of birth
- 5 points: reports back their correct (approximate) age
- 5 points: reports correct (approximate) year of retirement
- 5 points: reports back average generation length
- 5 points: reports correct (approximate) year for parents' births
- 5 points: reports correct (approximate) year for grandparents' births
- 5 points: asks user to say "Hi" to their grandparents
- 5 points: uses blank lines between the parts as shown in the sample output
- 5 points: opening comment is javadoc and includes student's name and A-number
- 10 points: code uses correct style (indentation, line length, etc.)
- 5 points: user's reported birth year changes when value of current year variable changes
- 5 points: user's reported retirement year changes when value of retirement age variable changes
- 5 points: ancestors' reported birth years changes when value of generation length changes
Note:
There will be penalties for submissions that do not compile
(that Netbeans shows with those red squiggly underlines)
or that "crash" on sample input
(do input in an unexpected way).
The grader may assign a grade of zero
if they deem the code too hard to fix.
SUBMIT
/
Check