-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRatio.java
More file actions
40 lines (33 loc) · 756 Bytes
/
Ratio.java
File metadata and controls
40 lines (33 loc) · 756 Bytes
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
public class Ratio {
protected int numer;
protected int demer;
public static final Ratio ZERO = new Ratio();
private Ratio () {
this (4,9);
}
public Ratio (int numer,int demer) {
this.numer = numer;
this.demer = demer;
}
public boolean equals(Object su){
if (su==this) {
return true;
}else if (!(su instanceof Ratio)) {
return false;
}
Ratio that = (Ratio)su;
return (this.numer*that.demer == that.numer*this.demer);
}
public int getNumer() {
return numer;
}
public int getDemer() {
return demer;
}
public String toString() {
return String.format("%d/%d", numer, demer);
}
public double value() {
return (double)numer/demer;
}
}