0% found this document useful (0 votes)
6 views2 pages

Review Classes

The document outlines the implementation of three classes: Point2D, Triangle, and Fraction. Each class includes private instance variables, overloaded constructors, and public methods for accessing and manipulating their data. The Point2D class handles 2D coordinates, the Triangle class manages width and height, and the Fraction class performs arithmetic operations on fractions.

Uploaded by

hieuldse180535
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Review Classes

The document outlines the implementation of three classes: Point2D, Triangle, and Fraction. Each class includes private instance variables, overloaded constructors, and public methods for accessing and manipulating their data. The Point2D class handles 2D coordinates, the Triangle class manages width and height, and the Fraction class performs arithmetic operations on fractions.

Uploaded by

hieuldse180535
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Review Classes, Objects, Methods and Exception

1. A class called Point2D is designed as shown in the following class


diagram. It contains:
• Two private instance variables: x (of the type double) and y (of the type
double), with default 0.0 and 0.0, respectively.
• Two overloaded constructors: a default constructor with no argument, and
a constructor that takes 2 double arguments for x coordinate and y coordinate.
• Two public methods: getX() and getY(), which return the x coordinate and
the y coordinate of this instance, respectively.
Implement Point class based on the definition.
Point2D
- x: float = 0.0f
- x: float = 0.0f

+ Point2D ()
+ Point2D (x: float, y: float)
+ getX(): float
+ getY(): float

2. Implement the Triangle class is defined as the following figure.


Triangle
- width: float = 0.0f
- height: float = 0.0f

+ Triangle ()
+ Triangle (width: float, height: float)
+ get Width (): float
+ get Height (): float
+ set Width (width: float)
+ set Height (height: float)
+ toString()

3. Implement the Fraction class is defined as the following figure.


Fraction
- numerator: int
- denominator: int

+ Fraction ()
+ Fraction(numerator: int, denominator: int)
Fraction(fraction: Fraction)
+ getNumerator(): int
+ setNumerator(numerator: int)
+ getDenominator (): int
+ setDenominator (denominator: int)
+ add(fraction: Fraction): Fraction
+ sub(fraction: Fraction): Fraction
+ mul(fraction: Fraction): Fraction
+ div(fraction: Fraction): Fraction
+ reducer(): void
+ toString()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy