CSC1110 Exercise - Week 1
Overview
This exercise will give you practice with declaring and initializing variables as well as using those variable in basic operations and print statements.
Instructions:
Setup:
- Before you start, complete the instructions for setting up WSL
- Make a new file with nano called Execise1.java and open it with nano. You can use the
touch
command to create an empty file.
touch Exercise1.java
nano Exercise1.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 Exercise1 {
public static void main(String[] args) {
}
}
Prompts
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 two variables that store the number of cats and dogs someone may own. Create a third variable that stores the total number of pets (cats plus dogs) they own. Print a statement that says how many cats, dogs, and total pets they own.
- Create two variables that store your first and last name. Print a statement that says your full name and some message.
- Create two variables that store the number of friends and donuts someone has. Make a third variable that stores the number of whole pieces that each friend gets. Print a statement with the number of friends, donuts, whole donuts per friend, and remaining donuts.
- Create two variables that hold the value of pi and the circumference of a circle. Create three more variables that store this circle's diameter, radius, and area. Print a statement that says the circle's circumference, diameter, radius, and area.
Sample Output
I have 2 cats and 1 dogs for a total of 3 pets.
Hello. My name is Janet Mayfair.
I have 23 donuts and 4 friends.
Each friend gets 5 whole donuts.
There will be 3 remaining donuts.
A Circle with a circumference of 10.0 has a:
diameter of 3.184713375796178
radius of 1.592356687898089
area of 7.961783439490445
Submission
See your professor's instructions for details on submission guidelines and due dates.