7
answers
0
watching
378
views

Write a class called fraction with the specifications below:
Class: Fraction
Data Members:
int numerator
int denominator
Methods:
Fraction()
Fraction(int numerator)
Fraction(int numerator, int
denominator) public void
setNumerator(int n) public void
setDenominator(int d) public int
getNumerator() public int
getDenominator() public double
getValue() public String toString() public
boolean equals(fraction)
Both instance variables have a default value of 1, and the denominator can't
be 0. No negatives are allowed, so all values must be positive.
The getValue() method calculates and returns the decimal value of the
fraction. For example, a fraction 1/2 (numerator is 1 and denominator is 2)
will have a value of 0.5.
The toString() method returns a String representation of a fraction in the
form n/d where n is the numerator and d is the denominator. The equals()
method takes another fraction and returns true if this fraction is equal to the
fraction on which the equals() method is invoked. Two fractions are equal if
their values are the same (i.e. 2/4 is equal to 1/2). 

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Avatar image
Read by 2 people
Already have an account? Log in
Avatar image
Read by 3 people
Already have an account? Log in
Avatar image
Read by 4 people
Already have an account? Log in

Related questions

Related Documents

Weekly leaderboard

Start filling in the gaps now
Log in