Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package IntroToJava;
- import java.util.Arrays;
- import java.util.Scanner;
- public class VehiclePark {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] vehicles = scanner.nextLine().split(" ");
- int countSold = 0;
- while (true) {
- String newVech = scanner.nextLine();
- if (newVech.equals("End of customers!")) {
- break;
- }
- char type = newVech.charAt(0);
- int seats = Integer.parseInt(newVech.split(" ")[2]);
- String car = (type + "" + seats).toLowerCase();
- boolean sold = false;
- for (int i = 0; i < vehicles.length; i++) {
- if (car.equals(vehicles[i])) {
- int price = (type + 32) * seats;
- vehicles[i]="";
- countSold++;
- System.out.printf("Yes, sold for %d$\n", price);
- sold = true;
- break;
- }
- }
- if (!sold) {
- System.out.println("No");
- }
- }
- String output = "Vehicles left: ";
- for (String v:vehicles
- ) {
- if(!v.isEmpty()){
- output+=v+", ";
- }
- }
- System.out.println(output.substring(0,output.length()-2));
- System.out.println("Vehicles sold: "+countSold);
- }
- }
Add Comment
Please, Sign In to add comment