forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogicMethods.java
More file actions
211 lines (155 loc) · 4.96 KB
/
Copy pathLogicMethods.java
File metadata and controls
211 lines (155 loc) · 4.96 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import java.util.Scanner;
public class LogicMethods
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("What size cheese would you like? ");
int diameter = in.nextInt();
System.out.println();
if (diameter < 0 || diameter > 3)
{
System.err.println("Your order is too crazy! Please try again.");
return;
}
System.out.println("How many yards of cheese would you like? ");
int yards = in.nextInt();
System.out.println();
if (yards < 0 || yards > 1000000)
{
System.err.println("Your order is too crazy! Please try again.");
return;
}
crazyCheesePrice(diameter,yards);
}
private static void crazyCheesePrice(int diameter, int yards)
{
int costPerYard = 0;
final int PRICE_ONE_INCH = 2;
final int PRICE_TWO_INCH = 4;
final int PRICE_THREE_INCH = 6;
if (diameter == 1)
{
costPerYard = (PRICE_ONE_INCH * yards);
} else if (diameter == 2)
{
costPerYard = (PRICE_TWO_INCH * yards);
} else if (diameter == 3)
{
costPerYard = (PRICE_THREE_INCH * yards);
}
int shipping = 0;
final int SHIPPING_ONE_OR_TWO = 2;
final int SHIPPING_THREE = 4;
final int FREE_SHIPPING_ONE_INCH = 50;
final int FREE_SHIPPING_TWO_INCHES = 75;
final int FREE_SHIPPING_THREE_INCHES = 25;
if ((diameter == 1 && yards <= FREE_SHIPPING_ONE_INCH) || (diameter == 2 && yards <= FREE_SHIPPING_TWO_INCHES))
{
shipping = SHIPPING_ONE_OR_TWO * yards;
} else if (diameter == 3 && yards <= FREE_SHIPPING_THREE_INCHES)
{
shipping = SHIPPING_THREE * yards;
}
final int HANDLING = 5;
int totalPrice = costPerYard + shipping + HANDLING;
System.out.println("The total cost for your order is $" + totalPrice);
System.out.println();
}
/* //5-4
private static void checkFermat(int a, int b, int c, int n)
{
if (n > 2)
{
if (Math.pow(a, n) + Math.pow(b, n) == Math.pow(c, n))
{
System.out.println("Holy smokes, Fermat was wrong!");
System.out.println();
} else
{
System.out.println("No, that doesn't work.");
System.out.println();
}
} else
{
System.out.println("Holy smokes, Fermat was right!");
System.out.println();
}
} */
//5-A
/*private static void printIsLarge(int number)
{
if (number > 99)
{
System.out.println("The number is large");
System.out.println();
}
}*/
//5-B
/*private static void printIsLargeOrSmall(int number)
{
if (number > 99)
{
System.out.println("The number is large");
System.out.println();
}
if (number < 10)
{
System.out.println("The number is small");
System.out.println();
}
}*/
//5-C
/*private static void printLargest(int number1, int number2)
{
if (number1 > number2)
{
System.out.println("The largest number is: " + number1);
System.out.println();
}
else if (number2 > number1) {
System.out.println("The largest number is: " + number2);
System.out.println();
}
else if (number1 == number2) {
System.out.println("The numbers are equal");
System.out.println();
}
} */
//5-D
/* private static void printLargestOdd(int number1, int number2)
{
int remainder1 = (number1 % 2);
int remainder2 = (number2 % 2);
if (remainder1 == 1 && remainder2 == 1)
{
if (number1 > number2)
{
System.out.println("The largest odd number is: " + number1);
System.out.println();
}
else if (number2 > number1) {
System.out.println("The largest odd number is: " + number2);
System.out.println();
}
else if (number1 == number2) {
System.out.println("Two odds make an even");
System.out.println(number1 + " + " + number2 + " = " + (number1 + number2));
}
}
else if (remainder1 == 1 && remainder2 == 0)
{
System.out.println("The largest odd number is: " + number1);
System.out.println();
}
else if (remainder1 == 0 && remainder2 == 1)
{
System.out.println("The largest odd number is: " + number2);
System.out.println();
}
else {
System.out.println("Neither number is odd");
System.out.println();
}
} */
}