Advertisement
Andreeva-Magdalena97

FanShop

Mar 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package ForLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FanShop {
  6.     public static void main(String[] args) {
  7.         Scanner s = new Scanner(System.in);
  8.  
  9.         int buget = Integer.parseInt(s.nextLine());
  10.         int n = Integer.parseInt(s.nextLine());
  11.         int item = 0;
  12.         int price = 0;
  13.         for (int i = 1; i<= n; i++){
  14.             String art = s.nextLine();
  15.  
  16.             if(art.equals("flag")){
  17.                 price += 15;
  18.  
  19.  
  20.             }
  21.             if(art.equals("hoodie")){
  22.                 price += 30;
  23.  
  24.             }
  25.             if(art.equals("keychain")){
  26.                 price += 4;
  27.  
  28.             }
  29.             if(art.equals("T-shirt")){
  30.                 price += 20;
  31.  
  32.             }
  33.             if(art.equals("sticker")){
  34.                 price += 1;
  35.             }
  36.             item++;
  37.  
  38.         }
  39.         if(price <= buget){
  40.             System.out.printf("You bought %d items and left with %d lv.",item, buget - price);
  41.         }else {
  42.             System.out.printf("Not enough money, you need %d more lv.", Math.abs(price - buget));
  43.         }
  44.  
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement