CS 201 - Computer Science I - Fall 2004
Lab 1 - Variables, Assignments, and Expressions


Loyola College > Department of Computer Science > CS 201 > Labs > Lab 1

Due

Monday, September 20 at 11:59pm.
Labs submitted one day late will be assessed a 20% penalty. Labs will not be accepted more than one day late.
Write-up and print out due Wednesday at the beginning of class.

Objectives

Reading

Koffman and Wolz, sections 2.1 and 2.2
Examples from lecture

Assignment - Part 1

Enter and run the following Java program.
// file: LineCalculator
// by: Jim Glenn
// date: 8/26/2003
// version: 0.1


// Determines the slope-intercept equation of a line given by two
// points.

public class LineCalculator
{
     // Outputs the equation of the line through the points
     // (x1, y1) and (x2, y2).  Change the assignments to x1, y1, x2, and y2,
     // recompile, and rerun the program to use for different pairs of
     // points.
     //
     // @param args ignored

    public static void main(String[] args)
    {
        // the coordinates of the two points

	int x1, y1, x2, y2;
	x1 = 5;
	y1 = 11;
	x2 = 2;
	y2 = 5;

	// compute the slope and intercepts of the line through the points

	double slope, intercept;
	slope = y2 - y1 / x2 - x1;
	intercept = y1 - x1 * slope;
	
	// output the slope and intercept of the line
	
	System.out.println(slope);
	System.out.println(intercept);
    }
}

The program is supposed to determine the equation of the line between the points (5, 11) and (2, 5). After running the program, it should be evident that there are errors in it. Find and fix those errors by doing the following.

Once you have fixed the first two errors, make the output more informative. Using a single System.out.println statement, make the output of the program look like

The equation of the line is y = 2.0x + 1.0

Assignment - Part 2

Write a program called PerpendicularBisector<Last Name 1><Last Name 2> that outputs the equation of the perpendicular bisector of the line segment between two points. Your program should

Your program should be well formatted and commented. Your choice of variable names should be appropriate and your output should be user friendly. (Hint: You may start with the first program and make modifications to it.)

Test your program to make sure it works on different pairs of points. However, as for the program in part 1, there will be some pairs of points for which you can't make your program work (at least not until later in the semester). Think about what points will cause your program to fail.

Individual Write-Up

In this write-up you will describe each line of code in the perpendicular bisector program in terms of syntax and semantics, excluding comments. To begin, write an introduction that describes the program. When describing your code, identify the class and method headers. You should explain your choice of types for your variables. Also, write out in normal mathematical formulation each of the formulas you use to calculate the Perpendicular Bisector. In the conclusion, include any comments or concerns you have pertaining to the lab.

This write up will be graded for quality of writing and use of technical terms.

Submissions

Submit the source code (.java file) for your corrected LineCalculator<Last Name 1><Last Name 2> class and your PerpendicularBisector<Last Name 1><Last Name 2> class using this webpage. Also, turn in a print out of your code as well as your write-ups by September 22 at the beginning of class.

Grading

Pairs for this lab

Section 1
Section 2