+ 4
Ballpark orders
I tried to solve the ballpark orders task. My code works but only 2 of the test cases are correct The others are hidden, could someone please have a look at this and tell me what might be the problem? https://code.sololearn.com/c1C9lHWl5ZWY/?ref=app
3 Réponses
+ 2
Here is my approach to this challenge, hope it helps
https://code.sololearn.com/cLuzI8GhC6S5/?ref=app
+ 1
Thanks
- 1
Try this
import java.util.Scanner;
public class BallParkOrders
{
static int getPrice (String s) {
switch (s) {
case "Nachos":
return 6;
case "Pizza":
return 6;
case "Cheeseburger":
return 10;
case "Water":
return 4;
default:
return 5;
}
}
public static void main(String[] args) {
Scanner clavier = new Scanner(System.in);
String order = clavier.nextLine();
String[] orders = order.split(" ");
int sum = 0;
double totalPrice = 0.0;
for (int i = 0; i < 4; i++) {
sum += getPrice(orders[i]);
}
totalPrice = sum*1.07;
System.out.printf("%.2f", totalPrice);
}
}