Unformatted text preview: CS 1050, Dr. Tucker Programming Assignment #5; Spring 2010
Feb 4/8
Due: Fri, Feb’ZEI'Qphlgl Number of points: 40
This programming assignment can be redone until Fri, Apr 2
Note: If you are handing in a revision, then hand in the
original graded version(s) also.
This program will be a revision of Programming Assignment #2 to use
a class. (See handout: Interactive Average with a Class) Write a Java class that will have 3 private instance variables (of type double) for the lengths of the sides of a triangle. The Java class should contain methods as follows: 1. A constructor that initializes the instance variables to default
values (your choice of values) (no parameters for this constructor) 2. A constructor with 3 parameters that initializes the instance
variables to be the values of the parameters. 3. A method that allows the user to input the lengths of the sides of
a triangle — include prompts  no error checking will be done 4. A method that outputs the lengths of the sides of the triangle
along with a message 5. A method that returns the perimeter of the triangle 6. A method that returns the area of the triangle This class should be placed in a file that is separate from the class containing the main program. Write a Java program to do the following: (setup your program so that
the steps are done in the order listed below). This code will be in‘a
file that is separate from the one for the class above. Note that the
main method should have perimeter and area as local variables. 1. Call a void method that Will output an explanation of what the
program does. Include in the explanation that this program uses
a class for the sides of a triangle and include your name. 2. Get the values of the lengths of the sides from the user  use
method from the class 3. Calculate the perimeter of the triangle — use method from the class
4. Calculate the area of the triangle — use method from the class 5. Use a void method to output, with appropriate messages:
The lengths of the sides of the triangle  use method from the
class, the perimeter of the triangle, and the area of the triangle. Style of your code should be similar to that of the first revised
version of Interactive Average which was handed out. Be sure to
include comments — programmer identification, assignment number,
section, purpose, and a brief explanation of the methods should appear
in the header comment. Include an explanation for all variables,
parameters and methods. Hand in: A printed copy of the source code — both files  do not use
screen prints. A screen print showing the output — you will need to
type in 3 numbers that are the lengths of the sides of a triangle. ...
View
Full Document
 Spring '10
 TUCKER
 Computer Science

Click to edit the document details