Docsity

Project 3 Syllabus - Computer Science I Major | CSC 1350, Lecture notes of Computer Science

Toggle sidebar
bg1
Implementing Classes CSc 1350: Project # 3
Implementing A LineSegment Class
Out: 2/25
Due: 3/9 by 11:50 PM
In this project you will implement a class to model a line segment.
Learning Objectives
•Implementing User-defined Classes
•Testing User-defined Classes
•Writing Interactive Programs
•Using The Math Class
One beauty of an object oriented language is that it allows a programmer
to employ abstraction in representing real world objects, including geometric
shapes. In this project you will implement a class that models a line segment.
You will then use objects of the class to create a the sides of a triangle and
calculate the area and perimeter of the triangle. A triangle is defined by
three line segments which are in turn defined by three pairs of x- and y-
coordinates. You will compute the perimeter and the area of the triangle.
You will than modify the line segments to form a new triangle and again
compute the perimeter and area of the new triangle.
1 The LineSegment Class
Read API documentation for the LineSegment class that I have on Moodle.
Specifically, read the field, method, and constructor summaries and details.
You will implement the LineSegment class.
Duncan 1 Spring 2012
pf3
pf4
pf5

Partial preview of the text

Download Project 3 Syllabus - Computer Science I Major | CSC 1350 and more Lecture notes Computer Science in PDF only on Docsity!

Implementing A LineSegment Class

Out: 2/ Due: 3/9 by 11:50 PM

In this project you will implement a class to model a line segment.

Learning Objectives

  • Implementing User-defined Classes
  • Testing User-defined Classes
  • Writing Interactive Programs
  • Using The Math Class

One beauty of an object oriented language is that it allows a programmer to employ abstraction in representing real world objects, including geometric shapes. In this project you will implement a class that models a line segment. You will then use objects of the class to create a the sides of a triangle and calculate the area and perimeter of the triangle. A triangle is defined by three line segments which are in turn defined by three pairs of x- and y- coordinates. You will compute the perimeter and the area of the triangle. You will than modify the line segments to form a new triangle and again compute the perimeter and area of the new triangle.

1 The LineSegment Class

Read API documentation for the LineSegment class that I have on Moodle. Specifically, read the field, method, and constructor summaries and details. You will implement the LineSegment class.

2 The LineSegmentTester Class

Write a client class to test your implementation of the LineSegment class that you implemented.

  1. Using an object of the Scanner class, your program will prompt the user for the x- and y- coordinates of three points. Your program will then create three line segments using these values as explicit parameters to the parameterized constructor of the LineSegment class: The first and second pairs of coordinates will be used for the start and end points, respectively, of the first line segment. The second and third pairs of coordinates will be used for the start and end points, respectively, of the second line segment. The third and first pairs of coordinates will be used for the start and end points, respectively, of the second line segment.
  2. Using accessor methods from the LineSegment class, your pro- gram will display the coordinates of the line segments that constitute the sides of a triangle, as shown in the sample run.
  3. Using the length method of the LineSegment class, your program will compute the perimeter of the triangle whose sides are the line seg- ments.
  4. Using the length method of the LineSegment class and the perime- ter calculated in step 3, your program will compute the area of the triangle whose sides are the line segments using Heron’s formula.
  5. Your program will then display both the perimeter and area of the triangle as shown in the sample run.
  6. Using an appropriate method of the LineSegment class, your program will modify the three line segments created in step 1:

(a) Move the end point of first line segment 5 pixels right-ward and 10 pixels downward. (b) Move the start point of the second line segment 5 pixels right-ward and 10 pixels downward. (c) Move the end point of the second line segment 5 pixels left-ward and 10 pixels downward.

A typical program interaction would be:

Sample Run:

Enter the x- and y- coordinates of the first point> 60 60 Enter the x- and y- coordinates of the second point> 100 100 Enter the x- and y- coordinates of the third point> 20 100

BEFORE TRANSFORMING:

The sides of the triangle are line 1:[(60.0,60.0)->(100.0,100.0)] line 2:[(100.0,100.0)->(20.0,100.0)] line 3:[(20.0,100.0)->(60.0,60.0)]

Perimeter = 193. Area = 1600.

AFTER TRANSFORMING:

The sides of the triangle are line 1:[(60.0,60.0)->(105.0,110.0)] line 2:[(105.0,110.0)->(15.0,110.0)] line 3:[(15.0,110.0)->(60.0,60.0)]

Perimeter = 224. Area = 2249.

Submitting Your Work

Compile your two Java source files (LineSegment.java and LineSegmentTester.java) until they are free of any syntax and/or semantic errors. Once you are satis- fied that your program properly compiles and is syntax and semantic error- free, submit your work. You may submit your work as many times as you wish once the due time has not elapsed. After the due time, any further submission will mean that you get no points for the project. Your program will be graded for both proper style and syntax.

  1. All source code files you submit must have a header with the following:

/**

  • @file filename
  • @author your name
  • @date xx-xx-xxxx
  • Description: describe what this file does
  • Course: CSC1350 Section X
  • pawsID: xxxxxxxx
  • Project #: 3
  • Instructor: Duncan */
  1. Include Javadoc style documentation for every method and field in the LineSegment class. You do not need to include Javadoc style documen- tation for the main method (in LineSegmentTester).
  2. Once you are convinced that your program works correctly, locate your source files (LineSegment.java and LineSegmentTester.java).
  3. Create a zip file myPawsID 3.zip and add the files to it, where my- PawsID is your LSU paws ID - the part of your LSU email address before the @ sign.
  4. Electronically submit your work for grading via Moodle using the dig- ital drop box.