+ 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

2nd Feb 2021, 10:56 AM
Anna
Anna - avatar
3 Antworten
+ 2
Here is my approach to this challenge, hope it helps https://code.sololearn.com/cLuzI8GhC6S5/?ref=app
13th May 2022, 9:01 PM
Adrian
+ 1
Thanks
27th Feb 2023, 11:38 PM
Yacine Mulre
Yacine Mulre - avatar
- 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); } }
13th Feb 2021, 3:07 PM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar