CS 115 Lab 7 Functions (Team)
Due Date: Monday, October 23, during class
Educational goals of this lab - verify that every student can
- write some graphics code
- write function definitions and call them
- use the graphics objects Line, Circle, Point
- using the Text object to display text messages on the graphics window
- work with their teammates to finish a project
Use this link to submit your team result.
Use the Lab 7 menu choice and "Code" as the type.
- Use this program as a start.
- (25 points) Write a main function which accomplishes
the task: In the graphics window, it will ask
the user to click three times,
draw line segments between the 3 points
(making a triangle) and find the total length of the 3 segments
using the distance function described below.
Then display the perimeter (total length of sides).
It must call the functions described below (distance, drawLine and drawPoint).
- (15 points) Write a distance function for the program that has 2 parameters.
The parameters are points (Points in the graphics sense).
You must use the getX and getY methods inside the function.
The function should calculate and return the distance
between the two points. It involves a square root.
You can use the math library function sqrt if you want.
This function does NOT output anything to the screen.
- (5 points) Write a function called "drawLine" which has 2 parameters which are Points
and one parameter which is a GraphWin.
It will create and draw a line between the two Points.
It draws it on the GraphWin.
- (15 points) Write a function called "drawPoint" which has one parameter, the graphics window. It gets a click from the user, draws a red Circle around that
point where they clicked, and returns the Point where they clicked.
- A sample run
- Another sample run
- (13 points) Now add another function called herons to this program.
This function will accept the lengths of 3 sides of a triangle (the parameters)
and calculate and return the area of the triangle (return value!).
It does not output anything to the screen.
This is the equation for the area.
s is the sum of the 3 sides divided by 2 (called a semiperimeter).
a, b, and c are the 3 lengths of the sides of the triangle.
- (7 points) The main function should be extended to call the herons function to find
the area of the triangle input by the mouse and output that to the
- Sample run: