CS 140 - Lab 2 Instructions

We will do this lab in class on Tuesday September 2.

Objectives

  1. Practice with Java's arithmetic expressions and variables.
  2. Write a Java program to calculate your CS140 course average.

Set Up

  1. One or two students should work at one workstation.
  2. In one student's account follow the instructions in the next section. To help choose whose account to use, pick the student who didn't log in last time. Work together. The person not typing should look for typos and other errors. Trade roles each lab session.

Calculating your CS140 Average

For this lab write all of your program in a file named Lab2.java in your CS140 folder on your P: drive. In the definitions pane (that's the largest window in the DrJava editor) start a skeleton class with the following:
  public class Lab2 {

     public static void main(String[] args) {
        // put your code here
     }
  }

Write all of your Java in the main method of the Lab2 class. Keep adding to your program as you work on parts of the lab.

Part I - Experimenting with types

  1. So far this semester Poindexter has a 12, 8, 17 on the three homeworks in CS140. The total possible number of points on each were 15, 10, and 20 respectively. Declare an appropriately typed variable named hwAvg to hold Poindexter's homework average. Write a Java expression to caculate that average and assign it to the variable. Let Java do all of the calculating, don't do any calculations in your head or use a calculator. Java is the ultimate calculator.
  2. Print Poindexter's homework average on the console nicely formatted to two decimal places. For example:
             Poindexter's homework average is 87.52%
          
    The actual average should be displayed where 87.52% is as a number between zero and one hundred to two decimal places. (I just made up the 87.52 and its not correct). Don't hardcode the average in the print statement, use the value held in the variable hwAvg.
  3. Completing a CS140 lab is worth two points. There have been ten labs so far but Poindexter has missed three. Calculate Poindexter's lab average (based on what my CS140 syllabus says about missing labs) and assign it to a variable named labAvg. Print the variable to the console with a nice message just like you did for the homework average.
  4. Poindexter got an 85 out of 100 on the first exam and a 5 out of 10 on the only quiz so far. Calculate Poindexter's current exam average and assign it to a suitably typed variable named examAvg. Again, let Java do all of the calculations. Print examAvg to the console to two decimal places with a nice message.
  5. Based on how homework, labs, and exams are weighted (see the syllabus), calculate Poindexter's overall CS140 class average, assign it to a variable named overallAvg and print it to the console with a nice message. Again let Java do all of the calculations.
  6. When you get to this point call me or Dan over to check off your lab.