-
Notifications
You must be signed in to change notification settings - Fork 0
/
MathFunction_jop.java
91 lines (88 loc) · 2.5 KB
/
MathFunction_jop.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
91
package mathfunction;
import javax.swing.JOptionPane;
public class MathFunction_jop {
private static String inDiag(String thisStuff) { //input diag shortcut
return JOptionPane.showInputDialog(thisStuff);
}
private static void msgBox(String thisStuff) { //message box shortcut
JOptionPane.showMessageDialog(null, thisStuff);
}
/*START MATH STUFF*/
private static void absolute() {
msgBox("The absolute value is " + Math.abs(Double.parseDouble(inDiag("Enter a value"))));
}
private static void ceiling() {
msgBox("The ceiling value is " + Math.ceil(Double.parseDouble(inDiag("Enter a value"))));
}
private static void floor() {
msgBox("The floor value is " + Math.floor(Double.parseDouble(inDiag("Enter a value"))));
}
private static void maxVal() {
msgBox("The largest value is " + Math.max(Double.parseDouble(inDiag("Enter a value")),Double.parseDouble(inDiag("Enter a value"))));
}
private static void power() {
msgBox("The exponential value is " + Math.pow(Double.parseDouble(inDiag("Enter a value")),Double.parseDouble(inDiag("Enter a value"))));
}
private static void random() {
msgBox("The random value is " + Math.random());
}
private static void round(){
msgBox("The rounded value is " + Math.round(Double.parseDouble(inDiag("Enter a value"))));
}
/*END MATH STUFF*/
public static void main(String[] args) {
boolean term = false;
while(!term) {
msgBox(
"Welcome to the Math Class and Method Program\n\n" +
"Select from the choices below\n\n" +
"---------------------------------------\n" +
" Code | Description \n"+
"---------------------------------------\n" +
" A | Absolute Value\n" +
" C | Ceiling Value\n" +
" M | Maximum Value\n" +
" P | Power Value\n" +
" T | Random Value\n" +
" R | Rounded Value\n"+
"---------------------------------------\n" +
" E | Exit\n" +
"---------------------------------------\n"
);
switch(inDiag("Enter the letter of your choice")) {
case "A":
case "a":
absolute();
break;
case "C":
case "c":
ceiling();
break;
case "F":
case "f":
floor();
break;
case "M":
case "m":
maxVal();
break;
case "P":
case "p":
power();
break;
case "T":
case "t":
random();
break;
case "R":
case "r":
round();
break;
case "E":
case "e":
term = true;
break;
}
}
}
}