Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class demo4 {
- public static void main(String[] agrs) {
- Scanner scanner = new Scanner(System.in);
- int count = Integer.parseInt(scanner.nextLine());
- int budget = Integer.parseInt(scanner.nextLine());
- double moneySpent = 0;
- for (int i = 0; i < count; i++) {
- String gift = scanner.nextLine().toLowerCase();
- if (gift.equals("sand clock")) {
- moneySpent += 2.20;
- } else if (gift.equals("magnet")) {
- moneySpent += 1.50;
- } else if (gift.equals("cup")) {
- moneySpent += 5;
- } else if (gift.equals("t-shirt")) {
- moneySpent += 10;
- }
- }
- if (moneySpent > budget) {
- double result = moneySpent - budget;
- System.out.printf("Santa Claus will need %.2f more leva.", result);
- } else {
- double result = budget - moneySpent;
- System.out.printf("Santa Claus has %.2f more leva left!", result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement