Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Exam2829July2018;
- import java.util.Scanner;
- public class FanShop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int budget = Integer.parseInt(scanner.nextLine());
- int n = Integer.parseInt(scanner.nextLine());
- int sum = 0;
- for (int i = 1; i <= n; i++) {
- String item = scanner.nextLine();
- int price = 0;
- if (item.equals("hoodie")) {
- price = 30;
- } else if (item.equals("keychain")) {
- price = 4;
- } else if (item.equals("T-shirt")) {
- price = 20;
- } else if (item.equals("flag")) {
- price = 15;
- } else {
- price = 1;
- }
- sum += price;
- }
- int diff = Math.abs(sum - budget);
- if (budget >= sum) {
- System.out.printf("You bought %d items and left with %d lv.", n, diff);
- } else {
- System.out.printf("Not enough money, you need %d more lv.", diff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement