Description
You’ve now been introduced writing a program in Java. This means you can write simple, but useful programs! Given your newfound skills, you’ve been hired by a company to calculate the age of customers! You’ve been provided with a Java class, AgeCalculator that you need to fill in to the appropriate specifications.
Solution Description
For this assignment, you won’t be expected to write your own class. Instead, we’ll provide the class and you simply have to fill in the main method. Keep in mind that what you print out should match the defined output exactly. Deviation from what the output should be, even by a character or two, will result in lost points.
To start, save the following code in a file called AgeCalculator.java:
| public class AgeCalculator { public static void main(String[] args) { // Do not modify the following line.
int birthYear = Integer.parseInt(args[0]); // Part 1: // Part 2: } } |
Part 1: Calculate the age
Inside of the main method, create a variable called age that can hold integers. Assign to age the age of the subject. Assume that someone’s age is the difference between 2019 and their birth year.
Part 2: Report the age
Once you calculate the age, it’s time to print it out. Output should be in the form:
This person is [age] years old!
Testing your app
In order to test your program, you can run java AgeCalculator [birth year] with some example year. For example,
java AgeCalculator 1998 prints out This person is 21 years old!
java AgeCalculator 2001 prints out This person is 18 years old! ___
Allowed Imports
To prevent trivialization of the assignment, you are not allowed to import any classes or packages.
Feature Restrictions
There are a few features and methods in Java that overly simplify the concepts we are trying to teach. For that reason, do not use any of the following in your final submission:
- var (the reserved keyword)
- exit




