# Week 3 : Classes and Objects solution

\$14.99

Original Work ?

## Description

Question 1
Write a class Triangle, which has two member variables base of type int, and height of type int.

Write a constructor which initialises the base and the height of a Triangle instance.

Write a method getArea() that returns the area of the Triangle as a double.

Write a method show(), to print the dimensions and area of the Triangle instance.

Write a method compare(Triangle t1, Triangle t2), which determines compares the area of two given Triangle objects (hint: recall the Float class compare() method used in Lab #2).

In the main method of the Triangle class, obtain user input for the Triangle’s base and height.
If the user wishes to do a comparison, ask for the dimensions of Triangle t1 and Triangle t2.

You may like to use the control loop from Lab #2 Question #2.

Test cases:

Test Input
Expected Output
base = 10, height = 10
50.0
base = 0, height = 10
Error – base / height cannot be 0 or negative
base = 10, height = -100
Error – base / height cannot be 0 or negative
t1 base = 10, height = 50
t2 base = 5, height = 100
t1 and t2 are equal
t1 base = 100, height = 50
t2 base = 5, height = 100
t1 is larger
t1 base = 10, height = -50
t2 base = 5, height = 100
Error – base / height cannot be 0 or negative
(The error message should appear right after t1’s dimensions have been entered)

Question 2

Implement the Equipment class from the IFCS, according to the following class diagram:

Equipment
– id : String
– description: String
+ Equipment(id:String, desc:String)
+ getId() : String
+ getDesc() : String

Write an IFCSManager class to maintain an array of Equipment objects. (Hint: refer to Lab #2 Question 2).

The IFCSManager will

remove an Equipment instance specified by its id
given an id, report if the Equipment instance resides in the Lab
display the list of Equipment instances in the Lab.
Test cases:

Test Input
Expected Output
id = 1234567
description = oscilloscope
id = null
description = oscilloscope
Error – id cannot be null
id = 1239999
description = null
Error – description cannot be null

remove Equipment instances

Test Input
Expected Output
id = 1234567
Equipment removed from Lab
id = null
Error – id cannot be null
id = abc123
Equipment with id abc123 cannot be found.

report Equipment instances

Test Input
Expected Output
id = 1234567
Equipment available in Lab
id = null
Error – id cannot be null
id = abc123
Equipment not in Lab.

display the list of Equipment instances in the Lab

Expected Output
id=123456, desc=oscilloscope
id=123457, desc=multimeter