Advertisement
MilaDimitrovaa

CarMain

Nov 29th, 2021
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner input = new Scanner(System.in);
  10.  
  11.         CarClass [] array = new CarClass[10];
  12.         String MARKA;
  13.         String MODEL;
  14.  
  15.         System.out.println("1. ADD");
  16.         System.out.println("2. REMOVE");
  17.         System.out.println("3. PRINT");
  18.         System.out.println("4. EXIT");
  19.  
  20.  
  21.         boolean check = true;
  22.  
  23.         while(check) {
  24.             System.out.println("Моля въведете опция от 1 до 4: ");
  25.             int choice = input.nextInt();
  26.             System.out.println();
  27.  
  28.             switch (choice) {
  29.  
  30.                 case 1:
  31.  
  32.                     System.out.print("Моля въведете МАРКА : ");
  33.                     MARKA = input.next();
  34.                     System.out.print("Моля въведете МОДЕЛ : ");
  35.                     MODEL = input.next();
  36.                     System.out.println();
  37.  
  38.                     for (int i = 0; i < array.length; i++) {
  39.                         if(array[i] == null){
  40.                             array[i] = new CarClass(MARKA,MODEL);
  41.                             break;
  42.                         }
  43.                     }
  44.  
  45.                     break;
  46.  
  47.  
  48.                 case 2:
  49.  
  50.                     System.out.print("Моля въведете МАРКА : ");
  51.                     MARKA = input.next();
  52.                     System.out.print("Моля въведете МОДЕЛ : ");
  53.                     MODEL = input.next();
  54.                     System.out.println();
  55.  
  56.                     for (int i = 0; i < array.length; i++) {
  57.                         if (array[i] != null) {
  58.                             if(array[i].getMarka().equals(MARKA) && array[i].getModel().equals(MODEL)){
  59.                             array[i] = null;
  60.                             break;
  61.                           }
  62.                         }
  63.  
  64.                     }
  65.  
  66.  
  67.                     break;
  68.  
  69.  
  70.                 case 3:
  71.                     for (CarClass car: array) {
  72.                         if(car != null){
  73.                             System.out.println(car.getMarka() + " " + car.getModel());
  74.                         }
  75.                     }
  76.  
  77.                     break;
  78.  
  79.  
  80.                 case 4:
  81.                     System.out.println("END");
  82.  
  83.                     check = false;
  84.  
  85.                     break;
  86.  
  87.                 default:
  88.                     System.out.println("НЕВАЛИДНА КОМАНДА !");
  89.             }
  90.  
  91.         }
  92.  
  93.     }// end of main()
  94.  
  95. }// end of Class : CarMain
  96.  
  97.  
  98.  
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement