Skip to content

Commit 21c4a2c

Browse files
committed
New Tutoria & Labsheet Added ✅
Tut 3 Answer Lab 4, 5 Question
1 parent 2737e35 commit 21c4a2c

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
253 KB
Binary file not shown.
432 KB
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
class Calculation {
3+
4+
public static int addition(int n1, int n2) {
5+
return n1 + n2;
6+
}
7+
8+
public static int subtraction(int n1, int n2) {
9+
return n1 - n2;
10+
}
11+
}
12+
13+
class DemoApp {
14+
15+
public static void main(String[] args) {
16+
17+
Calculation.addition(3, 2);
18+
Calculation.subtraction(5, 3);
19+
}
20+
}
21+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
class Feet {
2+
private int feet;
3+
private int inches;
4+
5+
public Feet(int feet, int inches){
6+
this.feet = feet;
7+
this.inches = inches;
8+
}
9+
10+
// Copy the content of len to the new Feet Object.
11+
public Feet(Feet len) {
12+
this.feet = len.feet;
13+
this.inches = len.inches;
14+
}
15+
16+
17+
// Add f1+f2 feet and store in current feet
18+
public void add(Feet f1, Feet f2){
19+
int i = f1.inches + f2.inches;
20+
21+
this.feet = (f1.feet + f2.feet) + (i / 12);
22+
this.inches = i % 12;
23+
}
24+
25+
public void add(Feet f1) {
26+
int i = f1.inches + this.inches;
27+
28+
this.feet += f1.feet + (i / 12);
29+
this.inches = i % 12;
30+
}
31+
32+
// public static Feet add(Feet f1, Feet f2){}
33+
// can't add this because of duplicate
34+
35+
public static Feet add(Feet f1, Feet f2, Feet f3) {
36+
int i = f1.inches + f2.inches + f3.inches;
37+
38+
int feet = (f1.feet + f2.feet + f3.feet) + (i / 12);
39+
int inches = i % 12;
40+
41+
return new Feet(feet, inches);
42+
}
43+
44+
// Display a Length e.g 5’6”
45+
public void print() {
46+
System.out.println(feet + "'" + inches + '"');
47+
}
48+
49+
public void print(String msg) {
50+
System.out.println(msg + feet + "'" + inches + '"');
51+
}
52+
53+
public static void print(Feet f) {
54+
System.out.println(f.feet + "'" + f.inches + '"');
55+
}
56+
}
57+
58+
class Main {
59+
60+
public static void main(String[] args) {
61+
62+
Feet f1 = new Feet(5, 6);
63+
Feet f2 = new Feet(6, 7);
64+
65+
f1.print();
66+
f1.add(f1, f2);
67+
f1.print("Length : ");
68+
69+
Feet f = new Feet(f2);
70+
f.print("Clone f2 = ");
71+
72+
f1.add(f2);
73+
f1.print("Length : ");
74+
75+
Feet.print(f);
76+
77+
Feet f5 = Feet.add(f, f1, f2);
78+
Feet.print(f5);
79+
}
80+
81+
}

0 commit comments

Comments
 (0)