@AlephZero/

Trempiada

Java

No description

fork
loading
Files
  • Main.java
  • Node.java
  • Trempiada.java
  • Trempist.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.Scanner;

public class Main
{
  static Scanner reader = new Scanner(System.in);

  public static void main(String[] args)
  {
    Trempiada trempiada = new Trempiada();

    int input = menu();
    while (input != -1)
    {
      if (input == 1)
      {
        System.out.print("Enter a name: ");
        String name = reader.next();
        System.out.print("Enter destination: ");
        String dest = reader.next();
        trempiada.addTrempist(new Trempist(name, dest));
      }
      else if (input == 2)
      {
        System.out.println("Enter destinations, from closest to furthest. Type 'exit' to finish.");
        Node<String> destinations = null;
        String dest = reader.next();
        while (!dest.equals("exit"))
        {
          destinations = new Node<String>(dest, destinations);
          System.out.println("Enter destinations, from closest to furthest. Type 'exit' to finish.");
          dest = reader.next();
        }
        System.out.print("Enter number of places: ");
        int places = reader.nextInt();

        System.out.print("Passengers entered, from last to first: ");
        trempiada.tremp(destinations, places);
      }
      System.out.println("\nCurrent waiting list: " + trempiada.toString());

      input = menu();
    }
  }

  public static int menu()
  {
    System.out.println("\nMenu:");
    System.out.println("(1) Add Trempist to waiting list");
    System.out.println("(2) Add car");
    System.out.print("Enter a number, -1 to exit: ");

    int input = reader.nextInt();
    while (input != 1 && input != 2 && input != -1)
    {
      System.out.print(input + " is an illegal input, try again: ");
      input = reader.nextInt();
    }
    System.out.println();
    return input;
  }
}