18126

Untitled

Jun 8th, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.55 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Comparator;
  3. import java.util.Scanner;
  4. import java.util.stream.Stream;
  5.  
  6. public class Task {
  7.  
  8.     public static void Writing(String text) {
  9.         for (int i = 0; i < text.length(); i++) {
  10.             System.out.print("" + text.charAt(i));
  11.             try {
  12.                 Thread.sleep(1);
  13.             } catch (Exception e) {
  14.                 e.printStackTrace();
  15.             }
  16.         }
  17.     }
  18.  
  19.     public static void Waiting(String text, int n) {
  20.         for (int i = 0; i < text.length(); i++) {
  21.             System.out.print("" + text.charAt(i));
  22.             try {
  23.                 Thread.sleep(1);
  24.             } catch (Exception e) {
  25.                 e.printStackTrace();
  26.             }
  27.         }
  28.     }
  29.  
  30.     public static void main(String[] args) {
  31.         Scanner scan = new Scanner(System.in);
  32.         int spaces = 154;
  33.         int number = 1;
  34.         int parkingNumber = 1;
  35.         int firstSortedNumber = 74;
  36.         int[] spaceNumber = new int[spaces];
  37.         int[] spaceCheck = new int[spaces];
  38.         for(int i = 0; i < spaceCheck.length; i++) {
  39.             spaceCheck[i] = i;
  40.         }
  41.         double[] spaceSize = new double[spaces];
  42.         String[] spaceOwner = new String[spaces];
  43.         String[] spaceDescription = new String[spaces];
  44.         boolean running = true;
  45.         boolean choice = false;
  46.         boolean choiceSort = false;
  47.         boolean choiceRegister = false;
  48.         System.out.println("|----------Welcome!----------|\n");
  49.         Writing("Welcome to Ivan's parking slots.\n");
  50.         Writing("What would you like to do?");
  51.         while (running) {
  52.             System.out.println("\n1 - Register my parking slot.");
  53.             System.out.println("2 - Sort parking slots.");
  54.             int tempInt = Integer.parseInt(scan.nextLine());
  55.             while (!choice) {
  56.                 if (tempInt == 1) {
  57.                     choice = true;
  58.                     choiceRegister = true;
  59.                     System.out.println();
  60.                     break;
  61.                 } else if (tempInt == 2) {
  62.                     choice = true;
  63.                     choiceSort = true;
  64.                     System.out.println();
  65.                     break;
  66.                 } else {
  67.                     Writing(tempInt + " is not a valid number!\n");
  68.                     System.out.println("1 - Register my parking slot.");
  69.                     System.out.println("2 - Sort parking slots.");
  70.                     tempInt = Integer.parseInt(scan.nextLine());
  71.                 }
  72.             }
  73.             try {
  74.                 if (choiceRegister) {
  75.                     if (number <= spaces) {
  76.                         Writing("|===STARTING REGISTRATION===|\n");
  77.                         Writing("\t\t[");
  78.                         for (int i = 0; i < 7; i++) {
  79.                             Waiting("-", 800);
  80.                         }
  81.                         Writing("]");
  82.                         Writing("\n\nPlease, insert your first and last name: ");
  83.                         String tempString = scan.nextLine();
  84.                         spaceOwner[number - 1] = tempString;
  85.                         Writing("Please, insert parking slot's size(in square meters): ");
  86.                         double tempDouble = Double.parseDouble(scan.nextLine());
  87.                         spaceSize[number - 1] = tempDouble;
  88.                         Writing("Before getting your parking number, please input description: ");
  89.                         tempString = scan.nextLine();
  90.                         spaceDescription[number - 1] = tempString;
  91.                         Writing("Your parking number is: " + number + " (out of " + spaces + " parking slots)\n");
  92.                         spaceNumber[number - 1] = parkingNumber;
  93.                         System.out.println();
  94.                         Writing("Your parking space is successfully registered.\n\n");
  95.                         Writing("\nOwner: " + spaceOwner[number - 1]);
  96.                         Writing("\nNumber: " + spaceNumber[number - 1]);
  97.                         Writing("\nSize: " + spaceSize[number - 1]);
  98.                         Writing("\nDescription: " + spaceDescription[number - 1]);
  99.                         number++;
  100.                         parkingNumber++;
  101.                         System.out.println("\n|----------Have a nice day!----------|");
  102.                         choiceRegister = false;
  103.                         choice = false;
  104.                     } else {
  105.                         System.out.println("Sorry, no more free parking slots :(");
  106.                         choiceRegister = false;
  107.                         choice = false;
  108.                     }
  109.                 }
  110.             } catch (Exception e) {
  111.                 System.out.println("Error accused: " + e);
  112.                 choiceRegister = false;
  113.                 choice = false;
  114.             }
  115.             if (choiceSort) {
  116.                 choiceSort = false;
  117.                 choice = false;
  118.                 Writing("What would you like to do?\n");
  119.                 System.out.println("1 - Sort by parking slots");
  120.                 System.out.println("2 - Sort by parking owner");
  121.                 System.out.println("3 - Sort by parking size");
  122.                 Writing("Insert sorting method: ");
  123.                 tempInt = Integer.parseInt(scan.nextLine());
  124.                 if(tempInt == 1) {//by slots
  125.                     System.out.println("Slot : Owner : Size : Description");
  126.                     for (int i = (spaces - (spaces - firstSortedNumber)) - 1; i < spaces - (spaces - firstSortedNumber); i++) {
  127.                         System.out.printf("%d : %s : %.2f m2 : %s\n", i + 1, spaceOwner[i], spaceSize[i], spaceDescription[i]);
  128.                     }
  129.                     for (int i = 0; i < (spaces - (spaces - firstSortedNumber)) - 1; i++) {
  130.                         System.out.printf("%d : %s : %.2f m2 : %s\n", i + 1, spaceOwner[i], spaceSize[i], spaceDescription[i]);
  131.                     }
  132.                     for (int i = spaces - (spaces - firstSortedNumber); i < spaces; i++) {
  133.                         System.out.printf("%d : %s : %.2f m2 : %s\n", i + 1, spaceOwner[i], spaceSize[i], spaceDescription[i]);
  134.                     }
  135.                     System.out.println("Slot : Owner : Size : Description");
  136.                 } else if(tempInt == 2) {//by owner
  137.                     String[] spaceOwnerSort = new String[spaceOwner.length];
  138.                     System.arraycopy(spaceOwner, 0, spaceOwnerSort, 0, spaceOwner.length);
  139.                     System.out.println("Slot : Owner : Size : Description");
  140.                     for(int i = 0; i < spaceOwnerSort.length; i++) {
  141.                         if(spaceOwnerSort[i] == null) {
  142.                             spaceOwnerSort[i] = "Empty";
  143.                         }
  144.                     }
  145.                     for(int a = 0; a < spaceOwnerSort.length - 1; a++) {
  146.                         for(int b = a + 1; b < spaceOwnerSort.length; b++) {
  147.                             if(spaceOwnerSort[a].compareTo(spaceOwnerSort[b]) > 0 && !spaceOwnerSort[a].equals("Empty") && !spaceOwnerSort[b].equals("Empty")) {
  148.                                 String temp = spaceOwnerSort[a];
  149.                                 spaceOwnerSort[a] = spaceOwnerSort[b];
  150.                                 spaceOwnerSort[b] = temp;
  151.                             }
  152.                         }
  153.                     }
  154.                     for (int i = (spaces - (spaces - firstSortedNumber)) - 1; i < spaces - (spaces - firstSortedNumber); i++) {
  155.                         System.out.printf("%d : %s : %.2f m2 : %s\n", spaceCheck[i]+1, spaceOwnerSort[spaceCheck[i]], spaceSize[spaceCheck[i]], spaceDescription[spaceCheck[i]]);
  156.                     }
  157.                     for (int i = 0; i < (spaces - (spaces - firstSortedNumber)) - 1; i++) {
  158.                         System.out.printf("%d : %s : %.2f m2 : %s\n", spaceCheck[i]+1, spaceOwnerSort[spaceCheck[i]], spaceSize[spaceCheck[i]], spaceDescription[spaceCheck[i]]);
  159.                     }
  160.                     for (int i = spaces - (spaces - firstSortedNumber); i < spaces; i++) {
  161.                         System.out.printf("%d : %s : %.2f m2 : %s\n", spaceCheck[i]+1, spaceOwnerSort[spaceCheck[i]], spaceSize[spaceCheck[i]], spaceDescription[spaceCheck[i]]);
  162.                     }
  163.                 } else if(tempInt == 3) {//by size
  164.                     System.out.println("sorting by size");
  165.                 } else {
  166.                     Writing(tempInt + " is not a valid number!\n");
  167.                     choiceSort = true;
  168.                 }
  169.             }
  170.         }
  171.     }
  172. }
  173.  
Add Comment
Please, Sign In to add comment