CSC1110 Homework - Week 1
Variable Initialization and Printing
Overview:
This homework will give you practice with declaring and initializing variables as well as using those variable in basic operations and print statements.
Setup:
- Before you start, complete the instructions for setting up WSL
- Make a new file with nano called Homework1.java and open it with nano. You can use the
touch
command to create an empty file.
touch Homework1.java
nano Homework1.java
- Add a file header at the top of the file that indicates the course, term, assignment name, your name, and date. Your file header should look like the one shown but with the correct information.
/*
* Course: CSC1110 - 131
* Spring 2025
* Lab 1 - My First Program
* Name: Your Name
* Created: 1/25/2025
*/
- Below your file header, add the header for the class and main method.
public class Homework1 {
public static void main(String[] args) {
}
}
Instructions
Do the prompts below within the curly brackets of the main method. Your code should produce text that matches the sample output. You must take a screenshot of your output and submit it with your finished code.
You can use the characters â\nâ and â\tâ to insert new lines or tabs into your print statements. Also, each separate System.out.println() commands print text to a new line. You can even do an empty System.out.println(); to print an empty new line.
When doing the prompts, your variables should
- Have types that make sense for the data they store.
- Have descriptive names with proper style. See your reading for proper variable names.
- Be used when doing calculations or printing text to the screen. For example, if you declare a variable for your birth year and the current year, the initialization of your approximate age should look like the code snippet shown.
int birthYear = 1987;
int currYear = 2025;
int approxAge = currYear - birthYear;
System.out.println("If you were born in "+birthYear+" and it is currently "+currYear+" you are approximately "+approxAge+" years old.");
Prompts
- Create variables of the appropriate type and naming convention (i.e. camel case) and store the following data.
- Your first name
- Your last name
- First name of someone in your family with the same last name
- Current year
- Your birth year
- Birth year of the person with the same last name
- Conversion from meters to inches (make this a constant with the keyword final)
- Your height in meters
- Height in meters of the person with the same last name
- Use the variables you created in print statements to achieve the output shown, given your specific data.
Sample Output
My last name is Mayfair and my first name is Janet, so my full name is Janet Mayfair.
Jamie is a family member who shares my last name, so their full name is Jamie Mayfair.
It is currently 2022.
I was born in 1987, so I am about 35 years old.
Jamie was born in 2002, so they are about 20 years old.
The conversion from meters to inches is 39.3.
If my height in meters is 1.62, then it is 63.666 in inches.
If Jamie's height in meters is 1.57, then it is 61.701 in inches.
Submission
See your professor's instructions for details on submission guidelines and due dates.