-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopAssignment4.java
More file actions
39 lines (31 loc) · 1.02 KB
/
Copy pathLoopAssignment4.java
File metadata and controls
39 lines (31 loc) · 1.02 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
package java_core;
public class LoopAssignment4 {
void costCalculator (char typeOfFood, int distance, int qty){
int totalCost =0;
int costOfFood;
if ((typeOfFood=='V'|| typeOfFood=='v' || typeOfFood=='N' || typeOfFood=='n') && distance>0 && qty>=1){
if (typeOfFood=='v' || typeOfFood == 'V'){
costOfFood = 12;
}
else{costOfFood=15;
}
if(distance<=3){
totalCost = costOfFood*qty;
}
else if(distance <=6){
totalCost = (costOfFood*qty) + (distance-3);
}
else if(distance >6){
totalCost = (costOfFood*qty)+ 3 + ((distance-6)*2);
}
}
else{
totalCost = -1;
}
System.out.println(totalCost);
}
public static void main(String args[]){
LoopAssignment4 object1 = new LoopAssignment4();
object1.costCalculator('v', 7, 1);
}
}