-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyRoutineDriver.java
More file actions
78 lines (69 loc) · 2.08 KB
/
MyRoutineDriver.java
File metadata and controls
78 lines (69 loc) · 2.08 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**Driver for My Routine program, contains basic
* interactivity with options to add vertices,
* print all vertices, print all edges, and an
* option to quit the program
*/
package MyRoutine;
import java.io.*;
public class MyRoutineDriver
{
public static void main(String[] args) throws IOException
{
String place;
boolean done = false;
RoutineGraph myRoutine = new RoutineGraph();
System.out.println("Welcome to the My Routine program.\n"
+ "This program tracks the places you go and\n"
+ "how mant times they are visited.\n");
//while loop runs program until the user chooses to quit
while (!done)
{
System.out.println("Enter a letter to choose an option:");
System.out.println("\'A\'dd a place you have been - \'S\'how where you have visited"
+"\n\'T'rips between places (printed) - 'Q'uit the program.");
//add option to sort by most visits later
int choice = (getChar());
switch (choice)
{
case 'a':
System.out.println("Enter the name of the place visited: ");
place = getString();
myRoutine.addVertex(new Vertex(place));
break;
case 's':
System.out.println("Here are the places you've been:");
myRoutine.printRoutine();
System.out.println("----------------------------");
break;
case 't':
System.out.println("These are the trips you have made:");
myRoutine.printTrips();
System.out.println("----------------------------");
break;
case 'q':
done = true;
System.out.println("Thanks for using My Routine.");
break;
default:
System.out.println("Invalid entry, please enter first capital letter"
+ " of option you want to use.");
}
}
}
/**Method to read string input from user
*/
public static String getString() throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
return s.toLowerCase();
}
/**Method to read char, calls get string method for input
*/
public static char getChar() throws IOException
{
String s = getString();
return s.charAt(0);
}
}