Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Task {
- public static void Writing(String text) {
- for (int i = 0; i < text.length(); i++) {
- System.out.print("" + text.charAt(i));
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- public static void Waiting(String text, int n) {
- for (int i = 0; i < text.length(); i++) {
- System.out.print("" + text.charAt(i));
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int spaces = 154;
- int number = 1;
- int parkingNumber = 1;
- int firstSortedNumber = 74;
- int[] spaceNumber = new int[spaces];
- int[] spaceCheck = new int[spaces];
- for (int i = 0; i < spaceCheck.length; i++) {
- spaceCheck[i] = i;
- }
- double[] spaceSize = new double[spaces];
- String[] spaceOwner = new String[spaces];
- String[] spaceDescription = new String[spaces];
- String[] spaceOwnerSort = new String[spaceOwner.length];
- boolean running = true;
- boolean choice = false;
- boolean choiceSort = false;
- boolean choiceRegister = false;
- System.out.println("|----------Welcome!----------|\n");
- Writing("Welcome to Ivan's parking slots.\n");
- Writing("What would you like to do?");
- while (running) {
- System.out.println("\n1 - Register my parking slot.");
- System.out.println("2 - Sort parking slots.");
- int tempInt = Integer.parseInt(scan.nextLine());
- while (!choice) {
- if (tempInt == 1) {
- choice = true;
- choiceRegister = true;
- System.out.println();
- break;
- } else if (tempInt == 2) {
- choice = true;
- choiceSort = true;
- System.out.println();
- break;
- } else {
- Writing(tempInt + " is not a valid number!\n");
- System.out.println("1 - Register my parking slot.");
- System.out.println("2 - Sort parking slots.");
- tempInt = Integer.parseInt(scan.nextLine());
- }
- }
- try {
- if (choiceRegister) {
- if (number <= spaces) {
- Writing("|===STARTING REGISTRATION===|\n");
- Writing("\t\t[");
- for (int i = 0; i < 7; i++) {
- Waiting("-", 800);
- }
- Writing("]");
- Writing("\n\nPlease, insert your first and last name: ");
- String tempString = scan.nextLine();
- spaceOwner[number - 1] = tempString;
- Writing("Please, insert parking slot's size(in square meters): ");
- double tempDouble = Double.parseDouble(scan.nextLine());
- spaceSize[number - 1] = tempDouble;
- Writing("Before getting your parking number, please input description: ");
- tempString = scan.nextLine();
- spaceDescription[number - 1] = tempString;
- Writing("Your parking number is: " + number + " (out of " + spaces + " parking slots)\n");
- spaceNumber[number - 1] = parkingNumber;
- System.out.println();
- Writing("Your parking space is successfully registered.\n");
- System.out.println("----------Have a nice day!----------");
- Writing("\nOwner: " + spaceOwner[number - 1]);
- Writing("\nNumber: " + spaceNumber[number - 1]);
- Writing("\nSize: " + spaceSize[number - 1]);
- Writing("\nDescription: " + spaceDescription[number - 1]);
- System.out.println();
- System.out.println();
- number++;
- parkingNumber++;
- System.out.println("\n|------------------------------------|");
- choiceRegister = false;
- choice = false;
- } else {
- System.out.println("Sorry, no more free parking slots :(");
- choiceRegister = false;
- choice = false;
- }
- }
- } catch (Exception e) {
- System.out.println("Error accused: " + e);
- choiceRegister = false;
- choice = false;
- }
- if (choiceSort) {
- for (int i = 0; i < spaceCheck.length; i++) {
- spaceCheck[i] = i;
- }
- choiceSort = false;
- choice = false;
- Writing("What would you like to do?\n");
- System.out.println("1 - Sort by parking slots");
- System.out.println("2 - Sort by parking owner");
- System.out.println("3 - Sort by parking size");
- Writing("Insert sorting method: ");
- tempInt = Integer.parseInt(scan.nextLine());
- if (tempInt == 1) {//by slots
- System.out.println("Slot : Owner : Size : Description");
- for (int i = (spaces - (spaces - firstSortedNumber)) - 1; i < spaces - (spaces - firstSortedNumber); i++) {
- System.out.printf("%d : %s : %.2f m2 : %s\n", i + 1, spaceOwner[i], spaceSize[i], spaceDescription[i]);
- }
- for (int i = 0; i < (spaces - (spaces - firstSortedNumber)) - 1; i++) {
- System.out.printf("%d : %s : %.2f m2 : %s\n", i + 1, spaceOwner[i], spaceSize[i], spaceDescription[i]);
- }
- for (int i = spaces - (spaces - firstSortedNumber); i < spaces; i++) {
- System.out.printf("%d : %s : %.2f m2 : %s\n", i + 1, spaceOwner[i], spaceSize[i], spaceDescription[i]);
- }
- System.out.println("Slot : Owner : Size : Description");
- } else if (tempInt == 2) {//by owner
- System.arraycopy(spaceOwner, 0, spaceOwnerSort, 0, spaceOwner.length);
- System.out.println("Slot : Owner : Size : Description");
- for(int i = 0; i < spaceOwnerSort.length; i++) {
- if(spaceOwnerSort[i] == null) {
- spaceOwnerSort[i] = "Empty";
- }
- }
- for(int a = 0; a < spaceOwnerSort.length - 1; a++) {
- for(int b = a + 1; b < spaceOwnerSort.length; b++) {
- if(spaceOwnerSort[a].compareTo(spaceOwnerSort[b]) > 0 && !spaceOwnerSort[a].equals("Empty") && !spaceOwnerSort[b].equals("Empty")) {
- String temp = spaceOwnerSort[a];
- spaceOwnerSort[a] = spaceOwnerSort[b];
- spaceOwnerSort[b] = temp;
- }
- }
- }
- for (int i = (spaces - (spaces - firstSortedNumber)) - 1; i < spaces - (spaces - firstSortedNumber); i++) {
- System.out.printf("%d : %s : %.2f m2 : %s\n", spaceCheck[i]+1, spaceOwnerSort[spaceCheck[i]], spaceSize[spaceCheck[i]], spaceDescription[spaceCheck[i]]);
- }
- for (int i = 0; i < (spaces - (spaces - firstSortedNumber)) - 1; i++) {
- System.out.printf("%d : %s : %.2f m2 : %s\n", spaceCheck[i]+1, spaceOwnerSort[spaceCheck[i]], spaceSize[spaceCheck[i]], spaceDescription[spaceCheck[i]]);
- }
- for (int i = spaces - (spaces - firstSortedNumber); i < spaces; i++) {
- System.out.printf("%d : %s : %.2f m2 : %s\n", spaceCheck[i]+1, spaceOwnerSort[spaceCheck[i]], spaceSize[spaceCheck[i]], spaceDescription[spaceCheck[i]]);
- }
- } else if (tempInt == 3) {//by size
- int[] slots = new int[154];
- for (int i = 0; i < slots.length; i++) {
- slots[i] = i;
- }
- for (int i = 0; i < spaceSize.length; i++) {
- int temp = 0;
- for (int j = 0; j < spaceSize.length - i; j++) {
- if (spaceSize[i] < spaceSize[i + j]) {
- temp = slots[i];
- slots[i] = slots[i + j];
- slots[i + j] = temp;
- }
- }
- }
- System.out.println("Slot : Owner : Size : Description");
- for (int i = (spaces - (spaces - firstSortedNumber)) - 1; i < spaces - (spaces - firstSortedNumber); i++) {
- System.out.printf("%d : %s : %.2f m2 : %s\n", slots[i] + 1, spaceOwner[slots[i]], spaceSize[slots[i]], spaceDescription[slots[i]]);
- }
- for (int i = 0; i < (spaces - (spaces - firstSortedNumber)) - 1; i++) {
- System.out.printf("%d : %s : %.2f m2 : %s\n", slots[i] + 1, spaceOwner[slots[i]], spaceSize[slots[i]], spaceDescription[slots[i]]);
- }
- for (int i = spaces - (spaces - firstSortedNumber); i < spaces; i++) {
- System.out.printf("%d : %s : %.2f m2 : %s\n", slots[i] + 1, spaceOwner[slots[i]], spaceSize[slots[i]], spaceDescription[slots[i]]);
- }
- System.out.println("Slot : Owner : Size : Description");
- } else {
- Writing(tempInt + " is not a valid number!\n");
- choiceSort = true;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment