Site Navigation

Site Search

CS 110: Lab 1 main content

Learning Objectives

After completion of this lab, you should be able to

Work collaboratively as a pair programming team

All labs in CS 110 will be done as pair programming teams. Your partner for today's lab is listed in the table below:

Hebeler 203
Grader: Vinh Tran; Assistant: Daniel Carpenter
Team 1
Aguilar Jr, Jaime
Akana, Christopher
Team 2
Amezcua Gutierrez, Edson
Awan, Samara
Team 3
Baird II, Owen
Barrett Wright, Matthew
Team 4
Berman, Jake
Bloom, Thomas
Team 5
Coudriet, Blake
Cuddington, Christopher
Team 6
Erickson, Joel
Field, Sarah
Team 7
Goeke, Maxwell
Hansen, Mitchell
Team 8
Harris, Alexander
Hastings, Jacob
Team 9
Heflick, Elizabeth
Hogan, Martin
Team 10
Hubbard, Ryan
Ling, Nathan
Team 11
McCauley, Rylee
Millard, Mikel
Team 12
Millard, Ryan
Nash, Christopher
Team 13
Olden, Gregory
Olivares, Scott
Team 14
Quayle, Weston
Shearer, Stetson
Team 15
Straub-Walden, Andrew
Wagster, Nathan
Team 16
Williamson, Sarah
Smith, Stephanie








Note: Partners will change every week.

You may wish to review basic pair programming guidelines before you begin.

You should change roles every 10 to 15 minutes.

Use test-driven development for developing software programs

In the last ten years, agile programmers have begun using test-driven development when developing software programs.

Test-driven development begins with writing test cases before writing program code. One advantage to beginning with test cases is ensuring that you understand the problem and its algorithmic solution.

Consider a dieter's problem of wanting to "walk off" the calories consumed from eating one or more Big Mac hamburgers. If you were the dieter and you really wanted to eat three Big Macs, how many miles would you need to walk to burn off the equivalent calories?

If this reminds you of a math problem, it should. Solving many types of problems on a computer involve mathematical calculations.

  1. Calories consumed = (number of Big Macs eaten) × (number of calories per Big Mac)
  2. Miles to burn it off = (calories consumed) ÷ (calories burned off per mile)

Here are two constants to work from

  1. Calories in one Big Mac = 590 calories
  2. Calories burned in one mile of walking = 93.5 calories per mile

Using a calculator (Windows calculator works fine), calculate the values for the four test cases given below

Test Cases
Big Macs EatenCalories ConsumedMiles to Walk It Off
0  
1  
3  
9  

Write your calculated test case values in the Lab 1 assignment sheet. You will turn in this sheet at the end of lab for credit.

Use jGRASP to type in a simple Java program

The Java source code below is a simple program to calculate the miles needed to walk to burn off a given number of calories

  1. Create a new Java file named BurnItOff.java saved in folder U:\labs\lab1 and type in the source code as accurately as you can

sourcecode (20K)

Change Pair Partner Roles

Change pair partner roles. The driver should become the navigator, the navigator should become the driver.

Use jGRASP to compile and execute a simple Java program

Most likely you will have made some minor typos when typing in the source code. Use jGRASP to help fix any compiler errors.

  1. Compile the program by clicking the compile button (the green plus icon) in the toolbar
    • Compiler error messages appear in the lower message pane of the jGRASP environment
    • FYI: Your program gets saved automatically every time you compile it
    • Tip: An easy way to help indent your program is to use the Generate CSD toolbar icon
  2. Fix any Compiler errors or warnings
    • Raise your hand and ask for help from the teaching assistant if you cannot figure out to fix a compiler error
    • Tip: It is a good idea to clear messages in the lower message pane between compiles to avoid getting confused

Change Pair Partner Roles

Change pair partner roles. The driver should become the navigator, the navigator should become the driver.

Test your program's correctness through execution

Now that the program is written and compiles correctly, run the program repeatedly to verify that it is correct

  1. Run the program by clicking the red running person icon in the toolbar
    • Output appears at the lower message pane of the jGRASP desktop
      • At the prompt, enter 0 for the number of Big Macs
      • Compare the program's output with your calculated miles needed to walk
  2. Re-run your program with the test values of 1 Big Mac, 3 Big Macs, and 9 Big Macs
    • You will need to re-compile and re-run your program to see the calories consumed

Write your program's output values for the test data on the Lab 1 assignment sheet. You will turn in this sheet at the end of lab for credit.

Note: Successfully testing with test data does not prove program correctness. It would be impossible (or at least too time-consuming) to test for every possible input value.

Modify your program to include French fries

Modify your program to allow the dieter to also eat and then walk-off French fries.

One medium package of MacDonald's French fries is 384 calories

Using a calculator (Windows calculator works fine), calculate the values for the four test cases given below

Test Cases
Big Macs EatenMedium French Fries EatenCalories ConsumedMiles to Walk It Off
00  
01  
12  
97  

Write your calculated test case values in the Lab 1 assignment sheet. You will turn in this sheet at the end of lab for credit.

Sample Session

How many Big Macs did you eat? 4
How many medium french fries did you eat? 5
Wow, you consumed 4280.0 calories
You need to walk 45.775401069518715 miles

Verify that your program is working correctly by comparing your program's output with your hand-calculated values.

Write your program's output values in the Lab 1 assignment sheet. You will turn in this sheet at the end of lab for credit.

To Receive Credit

You are allowed to drop one lab grade for the entire quarter. No late lab or program assignments are accepted.

Note: In-class lab time is not intended as free time for working on your program assignments. Only if you have completely solved the lab assignment, including all challenges, and have had your work checked off for completeness by your TA or professor should your begin the program assignment.