Advertisement
CoineTre

PreExam11/20_03.Football Souvenirs

Nov 18th, 2020 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FootballSouvenirs {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String team = scanner.nextLine();
  7.         String souvenirs = scanner.nextLine();
  8.         int numberSouvenirs = Integer.parseInt(scanner.nextLine());
  9.         double sumOfSouvenirs = 0.0;
  10.         double prices = 0.0;
  11.         boolean stocks = false;
  12.         boolean country = false;
  13.         switch (souvenirs) {
  14.             case "flags":
  15.                 if ("Argentina".equals(team)) {
  16.                     prices = 3.25;
  17.                 } else if ("Brazil".equals(team)) {
  18.                     prices = 4.20;
  19.                 } else if ("Croatia".equals(team)) {
  20.                     prices = 2.75;
  21.                 } else if ("Denmark".equals(team)) {
  22.                     prices = 3.10;
  23.                 } else {
  24.                     country = true;
  25.                 }
  26.                 break;
  27.             case "caps":
  28.                 if ("Argentina".equals(team)) {
  29.                     prices = 7.20;
  30.                 } else if ("Brazil".equals(team)) {
  31.                     prices = 8.50;
  32.                 } else if ("Croatia".equals(team)) {
  33.                     prices = 6.90;
  34.                 } else if ("Denmark".equals(team)) {
  35.                     prices = 6.50;
  36.                 } else {
  37.                     country = true;
  38.                 }
  39.                 break;
  40.             case "posters":
  41.                 if ("Argentina".equals(team)) {
  42.                     prices = 5.10;
  43.                 } else if ("Brazil".equals(team)) {
  44.                     prices = 5.35;
  45.                 } else if ("Croatia".equals(team)) {
  46.                     prices = 4.95;
  47.                 } else if ("Denmark".equals(team)) {
  48.                     prices = 4.80;
  49.                 } else {
  50.                     country = true;
  51.                 }
  52.                 break;
  53.             case "stickers":
  54.                 if ("Argentina".equals(team)) {
  55.                     prices = 1.25;
  56.                 } else if ("Brazil".equals(team)) {
  57.                     prices = 1.20;
  58.                 } else if ("Croatia".equals(team)) {
  59.                     prices = 1.10;
  60.                 } else if ("Denmark".equals(team)) {
  61.                     prices = 0.90;
  62.                 } else {
  63.                     country = true;
  64.                 }
  65.                 break;
  66.             default:
  67.                 stocks = true;
  68.                 break;
  69.         }
  70.         sumOfSouvenirs = prices * numberSouvenirs;
  71.         if (stocks){
  72.             System.out.println("Invalid stock!");
  73.         }else if(country){
  74.             System.out.println("Invalid country!");
  75.         }else{
  76.             System.out.printf("Pepi bought %d %s of %s for %.2f lv.", numberSouvenirs, souvenirs, team, sumOfSouvenirs);
  77.         }
  78.     }
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement