CSci 101: Homework 1


Objectives

In this assignment you will design and implement your own computer program. The problem description is given below.

Problem

Write a Java program that takes as input the lengths of the sides of a triangle, and outputs the area of that triangle to the screen.

Discussion

Your program should first output an introductory message to the user explaining what the program does. To get user input, you may use the SavitchIn class, as was done in the lab assignment. Each user input should be preceded by an output statement which prompts the user to enter the desired information. Once you have received the lengths of the sides of the triangle, use Hero's formula to calculate the area:

Let a, b and c represent the lengths of the sides of the triangle.
Let s be the semi-perimeter, and let A be the area.

Use the standard Java library function Math.sqrt to calculate the square root.

Sample Execution

This program will calculate the area of a triangle,
given the lengths of the sides of the triangle.

Enter the length of side a: 3
Enter the length of side b: 4
Enter the length of side c: 5

The triangle with sides of length 3, 4 and 5 has an area of 6.0

Testing

First, run your program on the sample data given above to make sure it returns the correct results. Then think of one other set of inputs to your program for the lengths of the sides of a triangle different from the example above, and manually calculate what the result should be. Finally, run your program on that test data to again ensure that it returns the correct results.

Deliverables

Turn in the following items:

  1. A printout of your program on paper
  2. A printout showing the 2 runs of your program specified in the Testing section above
  3. Staple these two items together and turn them in during class.

    Grading

    This assignment is worth 100 points total. Point values will be allocated as follows:

    Documentation consists of an introductory comment, meaningful identifier names, proper use of indentation and blank lines, and comments for each variable describing what it is used for. The program compiles and generates the correct results. Points will not be awarded for Functionality if the program does not compile. Introductory message to the user (don't forget this!), useful prompts, output properly labeled and formatted.