-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFraction.java
90 lines (81 loc) · 1.76 KB
/
Fraction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
Fraction Class to implement fractions (rational numbers)
*/
//public can be accessed by any client
//
public class Fraction
{
private int numerator;
private int denominator;
/**
Constructor
Fraction = 0/1
*/
public Fraction()
{
numerator = 0;
denominator = 1;
}
/**
Constructor
@param number The numerator, denominator = 1
*/
public Fraction(int num)
{
numerator = num;
denominator = 1;
}
/**
Constructor
@param num The numerator
@param den The denominator
*/
public Fraction(int num, int den)
{
numerator = num;
denominator = den;
}
/**
The setNumerator method stores a value in the
numerator field
@param num The value to be stored in numerator
*/
public void setNumerator(int num)
{
numerator = num;
}
/**
The setNumerator method stores a value in the
numerator field
@param num The value to be stored in numerator
*/
public void setDenominator(int den)
{
denominator = den;
}
/**
The getNumerator method returns a Fraction object's numerator
@return the value stored in the Fration's numerator field
*/
public int getNumerator()
{
return numerator;
}
/**
The getDenominator method returns a Fraction object's denominator
@return the value stored in the Fration's numerator field
*/
public int getDenominator()
{
return denominator;
}
/**
The getDecimal method returns a decimal representation of
the Fraction's numerator/denominator
@return the value numerator/denominator
*/
public double getDecimal()
{
return (double)numerator/denominator;
}
}