Site Navigation

Site Search

CS 110: Lab 13 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
Wagster, Nathan
Team 2
Amezcua Gutierrez, Edson
Smith, Stephanie
Team 3
Baird, Owen
Awan, Samara
Team 4
Berman, Jake
Bloom, Thomas
Team 5
Coudriet, Blake
Olden, Greg
Team 6
Erickson, Joel
Cuddington, Chris
Team 7
Goeke, Max
Straub-Walden, Andy
Team 8
Harris, Alexander
Williamson, Sarah
Team 9
Heflick, Liz
Hastings, Jake
Team 10
McCauley, Rylee
Quayle, Weston
Team 11
Millard, Ryan
Hogan, Martin
Team 12
Barrett Wright, Matthew
Ling, Nathan
Team 13
Millard, Mike
Nash, Chris
Team 14
Field, Sarah
Olivares, Scott
Team 15
Akana, Chris
Shearer, Stetson
Fill in: Hansen, Mitchell

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.

Write a LandTract class that contains an equals and toString method

Based on programming challenge #4 in your textbook

  1. Write a LandTract Java class that holds a tract's length and width (as doubles)
  2. Write the class constructor method that accepts two double arguments, one for the track's length and one for the width
  3. Write the getArea method that returns the tract's area
    • area = length * width
  4. Write a toString method that returns a string with the track's length, width, and area

For example, for a land track of 10 by 20, the toString method would return the string

   "length is 10.0, width is 20.0, area is 200.0"
  1. Write an equals method that accepts a LandTract object as the parameter and returns true if the two tracks have the same area, otherwise false
LandTract plot1 = new LandTract(10.0, 20.0);
LandTract plot2 = new LandTract(5.0, 40.0);

plot1.equals(plot2)
true

Change Pair Partner Roles

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

Test your LandTrack class

The following class LandTrackDemo may be used to test your LandTrack class

   import java.util.Scanner;

   public class LandTractDemo
   {
      public static void main(String[] args)
      {
      // local variables
         double length;          
         double width;       
         
      // Create a Scanner object for keyboard input
         Scanner keyboard = new Scanner(System.in);
     
      // Get the dimensions of tract 1
         System.out.print("Enter the length and width of Tract 1: ");
         length = keyboard.nextDouble();
         width = keyboard.nextDouble();
     
      // Create a LandTract object for tract 1
         LandTract tract1 = new LandTract(length, width);
     
      // Get the dimensions of tract 2
         System.out.print("Enter the length and width of Tract 2: ");
         length = keyboard.nextDouble();
         width = keyboard.nextDouble();
     
      // Create a LandTract object for tract 2
         LandTract tract2 = new LandTract(length, width);
     
      // Display the land tract data
         System.out.println("\nTRACT 1: " + tract1);
         System.out.println("TRACT 2: " + tract2 + "\n");
     
      // Determine whether the two tracts are equal
         if (tract1.equals(tract2))
            System.out.println("The tracts are the same size");
         else
            System.out.println("The tracts are NOT the same size");
      }
   }

Sample Session 1

Enter the length and width of Tract 1: 10.0 20.0
Enter the length and width of Tract 2: 15.0 25.0

TRACT 1: length is 10.0, width = 20.0, area = 200.0
TRACT 2: length is 15.0, width = 25.0, area = 375.0

The tracts are NOT the same size

Sample Session 2


Enter the length and width of Tract 1: 11.5 12.2
Enter the length and width of Tract 2: 12.2 11.5

TRACT 1: length is 11.5, width = 12.2, area = 140.29999999999998
TRACT 2: length is 12.2, width = 11.5, area = 140.29999999999998

The tracts are the same size

Change Pair Partner Roles

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

Factor in margin of error when comparing double values

Modify your LandTract equals method to consider two tracks of land as the same size if their areas are the same, plus or minus a rounding error of 0.01

Sample Session

Optional Challenge
Enter the length and width of Tract 1: 12.2222 13.3333
Enter the length and width of Tract 2: 13.3332 12.2223

TRACT 1: length is 12.2222, width = 13.3333, area = 162.96225926
TRACT 2: length is 13.3332, width = 12.2223, area = 162.96237036

The tracts are the same size

Test your program with a variety of different tracks of land to ensure it is working correctly.

To Receive Credit

You are allowed to drop one lab grade for the entire quarter.