CS 1063  Week 11:  Review and Exam 2

Assignments

Exam 2:  You should be able to:

Review:  The  Triangle Class

Triangle.java
TriangleTest.java
triangle.zip

Write a Triangle class that determines if three lengths form a triangle.  (The sum of any 2 sides must be greater than the 3rd.)  Your Triangle class should also determine what kind of triangle it is.

Equilateral - all three sides equal
Isosceles - two sides equal
scalene - no sides equal

The Triangle class has aconstructor that accepts the length of 3 sides as integers.  The private method boolean isTriangle() returns true if the sum of any two sides is greater than the third (3 tests) and if the sides form a triangle.  The method String toType() returns either "equilateral", "isosceles" or "scalene"; otherwise it returns "not a triangle".  You will also need a setSides method for easy testing.

Test your class with the following:
instantiate a Triangle object t with the sides 3,4,5
Print the type
set the sides to 1,2,1
Print the type
set the sides to 1,2,2
Print the type
set the sides to 2,2,2
Print the type

The RomanNumeral Class

RomanNumeral.java
RomanNumeralTest.java
romannumeral.zip

Write a program that prompts the user to enter a number within the range of 1 through 10.  The program should display the Roman numeral version of that number.  If the number outside the range of 1 through 10, the program should display an error message.  Write a class RomanNumeral with a constructor that accepts a positive number.  Your class should have two instance field variables in int myDecimalNumber and String myRomanNumeral.  Supply the usual getDecimalNumber, getRomanNumeral and toString methods.  Write a private method called convertToRomanNumeral that takes the decimal value and returns the appropriate roman numeral or an error message.  (This method can be called from the constructor to initialize myRomanNumeral.)

Review - Previous project 2 with solution

InternetService Project
InternetService Class Solution