MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / ADTFraction

Class ADTFraction

Programs/ADTFractionApp.java:19–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18
19class ADTFraction {
20 private int n; //numerator
21 private int d; //denomenator
22//---------------------------------------------------
23 public ADTFraction() {//default constructor
24 this.n=0;
25 this.d=1;
26 }
27//---------------------------------------------------
28 public ADTFraction(int a, int b) {//parameter constructor
29
30if(b!=0){
31 this.d=b;
32 this.n=a;
33}
34else{
35 this.n=0;
36 this.d=1;
37 System.out.println("Denomenator cannot be Zero");
38}
39
40
41 }
42//---------------------------------------------------
43 public void set(int a, int b) {//set numerator and denomenator
44 if(b!=0){
45 this.d=b;
46 this.n=a;
47}
48else{
49 this.n=0;
50 this.d=1;
51 System.out.println("Denomenator cannot be Zero");
52}
53 }
54
55
56
57//---------------------------------------------------
58 public ADTFraction plus(ADTFraction x) {//add two fractions this=3/5 x=7/8
59 int num, den;
60 den=this.d * x.d;
61 num=this.n * x.d + x.n * this.d;
62 ADTFraction f1 = new ADTFraction(num,den);
63 return f1;
64 }
65
66
67//---------------------------------------------------
68 public ADTFraction times(int a) {//multiply fraction by a number
69 int num, den;
70 den=this.d;
71 num=this.n * a;
72
73 ADTFraction f1 = new ADTFraction(num,den);
74 return f1;
75
76 //return times(new ADTFraction(a,1))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected