-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathClass.java
More file actions
82 lines (58 loc) · 1.87 KB
/
Copy pathMathClass.java
File metadata and controls
82 lines (58 loc) · 1.87 KB
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
package com.example.mathclass;
public class MathClass {
private static int a;
// an example method to use as a guideline
public void halve(double x) {
System.out.println(x / 2);
}
// I'll give you the first method's outline to fill in. For the rest, you're in charge of
// declaring the entire method.
public void square(int x) {
System.out.println(x * x);
}
// create your own methods here
public void averageFive(double a, double b, double c, double d, double e) {
System.out.println((a + b + c + d + e) / 5);
}
public void raiseToTheFourth(int x) {
System.out.println(x * x * x * x);
}
public void setKey(int x) {
a = x;
}
public void multiplyByKey(int x) {
System.out.println(a * x);
}
public static void keyCubed() {
System.out.println(a * a * a);
}
public static void makeInteger(double x) {
System.out.println((int)x);
}
public static void roundToNearestWhole(double x) {
System.out.println((int)(x+0.5) / 1);
}
public static void main(String args[]) {
MathClass tester = new MathClass();
// example method
// output: 4
tester.halve(8);
// you are in charge of making the rest of these work
// output: 49
tester.square(7);
// output: 7
tester.averageFive(7,10,5,7,6);
// output: 81
tester.raiseToTheFourth(3);
// output: nothing, just save the number 4 as an instance variable
tester.setKey(4);
// output: 28
tester.multiplyByKey(7);
// output: 64
tester.keyCubed();
// output: 3
tester.makeInteger(3.756);
// output: 8
tester.roundToNearestWhole(7.8);
}
}