COMP2243 - Programming and Problem Solving

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

OOP - Encapsulation Right Triangle OOP Program
RightTriangleClass.java
RightTriangleClient.java

Loan OOP Program
Loan.java
LoanCompany.java

Payroll OOP Program
PayrollClass.java
PayrollDepartment.java

Delivery OOP Program
PackageClass.java
DeliveryCompany.java

Fraction OOP Program
Fraction.java
FractionClient.java




Right Triangle OOP Program


Description

This is an OOP program that uses RightTriangle objects to calculate the areas and perimeters of right triangles.

The ADT (abstract data type) is RightTriangleClass.java.

The client program is RightTriangleClient.java.

Associated Concepts:

Object Oriented Programming (OOP)

Data member: instance variable

Instance method

Constructor

Getter and getter

toString method

Algorithm:

For RightTriangleClass, the class diagram is represented in UML (Unified Modeling Language) notation.



Client program:

Create the first object using the non-default constructor with the user input data

Use the object reference to call the methods to calculate the area and perimeter

Print the object's information

Create the second object using the default constructor

Set the second object's data members using setters

Use the object reference to call the methods to calculate the area and perimeter

Print the object's information

Compare two objects to determine which has the larger side 1

Double the size of the first object and print its information

Source Code