Guest User

Untitled

a guest
Sep 26th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. package IntroToJava;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class VehiclePark {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         String[] vehicles = scanner.nextLine().split(" ");
  10.         int countSold = 0;
  11.         while (true) {
  12.             String newVech = scanner.nextLine();
  13.             if (newVech.equals("End of customers!")) {
  14.                 break;
  15.             }
  16.             char type = newVech.charAt(0);
  17.             int seats = Integer.parseInt(newVech.split(" ")[2]);
  18.             String car = (type + "" + seats).toLowerCase();
  19.             boolean sold = false;
  20.  
  21.             for (int i = 0; i < vehicles.length; i++) {
  22.                 if (car.equals(vehicles[i])) {
  23.                     int price = (type + 32) * seats;
  24.                     vehicles[i]="";
  25.                     countSold++;
  26.                     System.out.printf("Yes, sold for %d$\n", price);
  27.                     sold = true;
  28.                     break;
  29.                 }
  30.             }
  31.             if (!sold) {
  32.                 System.out.println("No");
  33.             }
  34.         }
  35.         String output = "Vehicles left: ";
  36.         for (String v:vehicles
  37.              ) {
  38.             if(!v.isEmpty()){
  39.                 output+=v+", ";
  40.             }
  41.         }
  42.         System.out.println(output.substring(0,output.length()-2));
  43.         System.out.println("Vehicles sold: "+countSold);
  44.  
  45.     }
  46. }
Add Comment
Please, Sign In to add comment