CS 112
Fall 2025

Lab 1: Getting started

Task 0.0: Review lab policies

Note

You cannot get credit for completing the lab tasks at home and coming to lab only to sign the attendance sheet. Part of participation is attending the lab to interact and ask questions.

Task 1: The Basics

Using folders

We strongly encourage you to create a separate folder for each lab and each problem set, so that you can more easily keep track of your work. For example, you could create a folder called lab1 for your work on this lab, and put all of the files for this lab in that folder.

Task 1.2: Using VSCode

In Lab 0, you should have installed your IDE on your computer. If you have not, please do so ASAP.

To see how to use it, let’s take the following steps together:

  1. Let’s begin by creating an easy-to-access general folder on your computer where you can store all your code throughout the semester. Example: a CS112 general folder along with several subfolders one for each problem set assignment, lab, and anything else to keep things organized.

  2. Launch VSCode on your laptop. If you do not see the VSCode icon on your workspace, you can:

    • on Windows, use the Windows button in the lower-left corner of your Desktop to search for and run Visual Studio Code.

    • on macOS, use the Spotlight tool to search for and and run Visual Studio Code.

    You should begin on the Welcome page (if not, click on the File dropdown on the top left and select Close Folder).

  3. If you have not already done so, in your computer’s file explorer, create a folder called lab1 inside your CS112 folder (organization is up to you).

  4. Select the File->Open Folder or File->Open menu option, and use the resulting dialog box to find and open the lab1 folder that you created. The name of the folder should appear in a new Explorer pane on the left-hand side of the VS Code window.

  5. Let’s create our first java file. There are many ways to do this, but for now we’ll start with the easiest. To the right side on lab1 there should be an icon labelled “New File”. Select File->New File, which will open up an empty window known as an editor window for your new program. It will initially have a name that is something like Untitled-1.

  6. Select File->Save, and give the file the name HelloWorld.java.

  7. Now let’s write our first class. Don’t worry if you don’t understand the syntax yet, this is just an introduction. Copy the following code into the file:

    public class HelloWorld {
        public static void main(String[] args) {
           /* INSERT a line to output "Hello World" */
        }
     }
    
  8. Replace the comment with the statement to print the literal string “Hello World!”

  9. Save and run the program. There are many ways to this, but the easiest is to hit the Run button on the top right of the window.

A few useful tips when working with VSC:

Task 1.2: Debugging a Simple Program

Let’s start with a simple exercise to get used to the VSC Development environment. Download the following file (in your lab1 directory) on your computer.

Debugging.java

Open it up using VSC. Now pretend you are the Java compiler and try finding all the intentional bugs in the program. How many errors can you find?

  1. Fix all the errors and try to run your program. If you fixed all the compilation errors your program should run. If you did not find all the errors, look through the compiler errors to see if you can fix the remaining. Run your program once all the errors are fixed.

  2. Now look at the result. Is it correct? If not, there may be a logic error. Can you find it?

Task 2: Writing our first custom program

In case you are not able to complete this task or the challenge portion in lab today, it can be a fun weekend activity! Remember lab solutions will be posted!

  1. Write a Java program that greets you. Add code to the main method of your program to issue a prompt asking for your name, display a polite (or not so polite) greeting message and then prompt you to enter your age.

    Use the methods of the Scanner class to perform the user input. You should use the method next to read and return a string value and nextInt to read and return an integer value. Your program may run as follows:

    Please enter your name: Christine
    Hello Christine, Welcome to CS112!!!
    Christine how old are you? 61
    61! WOW!
    

Challenge (once comfortable with conditional logic):

  1. Enhance your program to output a personal insult based on the value of age that was entered. Use the following age cuttoffs for creating your insults:

    1 <= 10 everyone is sweet
    11 <= 17 they are dweebs
    18 <= 20 they are counting down to legal age
    21 exactly they just made legal age
    22 <= 29 they are counting down to 30
    30 <= 40 they are suffering adults
    41 < 50 they are miserable adults
    >= 50 you are speechless!!
    

    A few possible sample runs (but feel free to be creative!):

    Please enter your name: Aileen
    Hello Aileen, Welcome to CS112!!!
    Aileen how old are you? 21
    
    Wow Aileen! You just made it!
    
    Please enter your name: Mike
    Hello Mike, Welcome to CS112!!!
    Mike how old are you? 19
    
    Wow Mike! You have 2 more years to go!!
    
    Please enter your name: John
    Hello John, Welcome to CS112!!!
    John how old are you? 13
    
    Wow John! you are such a dweeb!!