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:

touch Homework1.java
nano Homework1.java
/*
 * Course: CSC1110 - 131
 * Spring 2025
 * Lab 1 - My First Program
 * Name: Your Name
 * Created: 1/25/2025
 */
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

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

  1. 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
  2. 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.