Advertisement
miknik97

Coooo

Mar 24th, 2018
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.87 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         int choice, chooseCar, i = 0;
  5.         String bufor;
  6.         Scanner scanner = new Scanner(System.in);
  7.         Car[] cars = null;
  8.         cars = new Car[100];
  9.         do {
  10.             System.out.println("Witaj w autolandii, co chcesz zrobić?");
  11.             System.out.println("1.Stwórz samochód...");
  12.             System.out.println("2.Usuń samochód...");
  13.             System.out.println("3.Modyfikuj samochód...");
  14.             System.out.println("4.Wyświetl samochód...");
  15.             System.out.println("0.Zakończ program...");
  16.             choice = scanner.nextInt();
  17.             bufor = scanner.nextLine();
  18.             switch (choice) {
  19.                 case 1:
  20.                     System.out.println("Tworzenie samochodu.");
  21.                     cars[i] = new Car();
  22.                     System.out.println("Podaj markę samochodu.");
  23.                     cars[i].brand = scanner.nextLine();
  24.                     System.out.println("Podaj model samochodu.");
  25.                     cars[i].model = scanner.nextLine();
  26.                     System.out.println("Podaj kraj produkcji samochodu.");
  27.                     cars[i].country = scanner.nextLine();
  28.                     System.out.println("Podaj rok produkcji samochodu.");
  29.                     cars[i].year = scanner.nextInt();
  30.                     bufor = scanner.nextLine();
  31.                     System.out.println("Podaj imię aktualnego właściciela.");
  32.                     cars[i].owners.firstName = scanner.nextLine();
  33.                     System.out.println("Podaj nazwisko aktualnego właściciela.");
  34.                     cars[i].owners.secondName = scanner.nextLine();
  35.                     System.out.println("Podaj liczbę poprzednich właścicieli.");
  36.                     cars[i].ownersNumber = scanner.nextInt();
  37.                     bufor = scanner.nextLine();
  38.                     System.out.println("Gotowe");
  39.                     i++;
  40.                     break;
  41.                 case 2:
  42.                     System.out.println("Usuwanie samochodu.");
  43.                     System.out.println("Lista samochodów:");
  44.                     for (int x = 0; x < i; x++) {
  45.                         System.out.printf("%d. %s %s\n", x + 1, cars[x].brand, cars[x].model);
  46.                     }
  47.                     System.out.println("Podaj, który samochód chcesz usunąć.");
  48.                     chooseCar = scanner.nextInt();
  49.                     if (chooseCar - 1 <= i && chooseCar > 0) {
  50.                         for (; chooseCar < i; chooseCar++) {
  51.                             cars[chooseCar - 1].brand = cars[chooseCar].brand;
  52.                             cars[chooseCar - 1].model = cars[chooseCar].model;
  53.                             cars[chooseCar - 1].country = cars[chooseCar].country;
  54.                             cars[chooseCar - 1].year = cars[chooseCar].year;
  55.                             cars[chooseCar - 1].owners.firstName = cars[chooseCar].owners.firstName;
  56.                             cars[chooseCar - 1].owners.secondName = cars[chooseCar].owners.secondName;
  57.                             cars[chooseCar - 1].ownersNumber = cars[chooseCar].ownersNumber;
  58.                         }
  59.                         i--;
  60.                     } else System.out.println("Samochód nie istnieje w bazie.");
  61.                     System.out.println("Gotowe");
  62.                     break;
  63.                 case 3:
  64.                     int chooseModify;
  65.                     System.out.println("Modyfikacja parametrów samochodu.");
  66.                     System.out.println("Lista samochodów:");
  67.                     for (int x = 0; x < i; x++) {
  68.                         System.out.printf("%d. %s %s\n", x+1, cars[x].brand, cars[x].model);
  69.                     }
  70.                     System.out.println("Podaj, który samochód chcesz zmodyfikować.");
  71.                     chooseCar = scanner.nextInt();
  72.                     if (chooseCar <= i && chooseCar > 0) {
  73.                         chooseCar--;
  74.                         System.out.println("Wybierz co chcesz zmodyfikować:");
  75.                         System.out.println("1.Marka.");
  76.                         System.out.println("2.Model.");
  77.                         System.out.println("3.Kraj.");
  78.                         System.out.println("4.Rok.");
  79.                         System.out.println("5.Imię aktualnego właściciela.");
  80.                         System.out.println("6.Nazwisko aktualnego właściciela.");
  81.                         System.out.println("7.Liczba poprzednich właścicieli.");
  82.                         chooseModify = scanner.nextInt();
  83.                         bufor = scanner.nextLine();
  84.                         switch (chooseModify) {
  85.                             case 1:
  86.                                 System.out.println("Podaj markę samochodu.");
  87.                                 cars[chooseCar].brand = scanner.nextLine();
  88.                                 break;
  89.                             case 2:
  90.                                 System.out.println("Podaj model samochodu.");
  91.                                 cars[chooseCar].model = scanner.nextLine();
  92.                                 break;
  93.                             case 3:
  94.                                 System.out.println("Podaj kraj produkcji samochodu.");
  95.                                 cars[chooseCar].country = scanner.nextLine();
  96.                                 break;
  97.                             case 4:
  98.                                 System.out.println("Podaj rok produkcji samochodu.");
  99.                                 cars[chooseCar].year = scanner.nextInt();
  100.                                 break;
  101.                             case 5:
  102.                                 System.out.println("Podaj imię aktualnego właściciela.");
  103.                                 cars[chooseCar].owners.firstName = scanner.nextLine();
  104.                                 break;
  105.                             case 6:
  106.                                 System.out.println("Podaj ilość dostępnych samochodów.");
  107.                                 cars[chooseCar].owners.secondName = scanner.nextLine();
  108.                                 break;
  109.                             case 7:
  110.                                 System.out.println("Podaj liczbę poprzednich właścicieli.");
  111.                                 cars[chooseCar].ownersNumber = scanner.nextInt();
  112.                                 break;
  113.  
  114.                             default:
  115.                                 System.out.println("Wybierz opcję od 1 do 7.");
  116.                                 break;
  117.                         }
  118.                     } else System.out.println("Samochód nie istnieje w bazie.");
  119.                     System.out.println("Gotowe");
  120.                     break;
  121.                 case 4:
  122.                     System.out.println("Wyswietlanie samochodu");
  123.                     System.out.println("Liczba samochodów w bazie: " + i);
  124.                     System.out.println("Podaj, który samochód chcesz wyświetlić.");
  125.                     chooseCar = scanner.nextInt();
  126.                     if (chooseCar <= i && chooseCar > 0) {
  127.                         chooseCar--;
  128.                         System.out.println("Model: " + cars[chooseCar].brand);
  129.                         System.out.println("Marka: " + cars[chooseCar].model);
  130.                         System.out.println("Kraj produkcji: " + cars[chooseCar].country);
  131.                         System.out.println("Rok produkcji: " + cars[chooseCar].year);
  132.                         System.out.println("Wiek samochodu w latach: " + cars[chooseCar].carAge());
  133.                         System.out.println("Imię i nazwisko właściciela: " + cars[chooseCar].owners.firstName +" "+ cars[chooseCar].owners.secondName);
  134.                         System.out.println("Liczba poprzednich właścicieli: " + cars[chooseCar].ownersNumber);
  135.                     } else System.out.println("Samochód nie istnieje w bazie.");
  136.                     System.out.println("Gotowe");
  137.                     break;
  138.                 case 0:
  139.                     break;
  140.                 default:
  141.                     System.out.println("Wybierz opcję od 1 do 4.");
  142.                     break;
  143.             }
  144.         } while (choice != 0);
  145.         System.out.println("Żegnaj!");
  146.     }
  147. }
  148.  
  149. ------------------------------------------------------------------------------------------------------------------------------------------
  150.  
  151. import java.time.Year;
  152. public class Car
  153. {
  154.     int currentYear = Year.now().getValue();
  155.     int year, ownersNumber;
  156.     String brand, model, country;
  157.     Owner owners = new Owner();
  158.     int carAge()
  159.     {
  160.         int age = currentYear - year;
  161.         return age;
  162.     }
  163. }
  164.  
  165. ------------------------------------------------------------------------------------------------------------------------------------------
  166.  
  167. public class Owner
  168. {
  169.     String firstName, secondName;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement