Repository navigation
Expand file tree
/
Copy pathCustomer
More file actions
167 lines (146 loc) · 4.95 KB
/
Copy pathCustomer
File metadata and controls
167 lines (146 loc) · 4.95 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class customer {
int ID;
String name;
String birthday;
public customer() {
}
customer(int cID, String cName, String dob){
this.ID = cID;
this.name = cName;
this.birthday = dob;
}
public static List<customer> customerObject = new ArrayList<>();
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public static void showOptions(){
System.out.println("1 --> View vehicles");
System.out.println("2 --> Make an appointment");
System.out.println("3 --> View appointments");
System.out.println("4 --> Exit");
}
public void viewCustomers(){
System.out.println("ID: "+getID());
System.out.println("Customer name: "+getName());
System.out.println("Customer birthday: "+getBirthday());
}
public static void addCustomer(customer customer){
customerObject.add(customer);
}
public static void removeCustomer(int ID){
for (customer customer: customerObject) {
if (customer.getID() == ID) {
customerObject.remove(customer);
}
}
}
public static void searchCustomer(int ID){
for(customer customer: customerObject){
if(customer.getID() == ID){
System.out.println("ID: "+customer.getID());
System.out.println("Customer name: "+customer.getName());
System.out.println("Customer birthday: "+customer.getBirthday());
}
}
}
public static void goBackCustomer() throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println("\nChoose from the below options");
System.out.println("1 --> Remain as customer");
System.out.println("2 --> Go to main menu");
System.out.println("3 --> Exit");
int exit = sc.nextInt();
if (exit == 1){
enterToC();
}
else if (exit == 2){
Main.mainMenu();
}
else {
System.out.println("\nExiting the program, have a good day!");
}
}
public static void maintenance() throws FileNotFoundException {
FileOutputStream fos = new FileOutputStream("askForAppointment.csv", true);
PrintWriter pw = new PrintWriter(fos);
Scanner sc = new Scanner(System.in);
System.out.println("Enter vehicle ID: ");
String vID = sc.nextLine();
System.out.println("Enter required assistance in short: ");
String job = sc.nextLine();
pw.println(vID+","+job);
pw.close();
}
public static void viewScheduledAppointments() {
String path = "scheduledAppointments.csv";
String line = "";
try {
BufferedReader br = new BufferedReader(new FileReader(path));
System.out.println("\nDetails of all vehicles in system:");
System.out.println("plateNumber,service,date,time");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void enterToC() throws IOException {
System.out.println("----------------------------------------------------------------------------------------------------");
Scanner b = new Scanner(System.in);
System.out.println("Enter Username:");
String userName = b.nextLine();
System.out.println("Enter Password:");
int passWord = b.nextInt();
if ((userName.equals("customer123")) && (passWord == 5678)) {
System.out.println("----------------------------------------------------------------------------------------------------");
customer.showOptions();
System.out.println("Enter index of task to be done:");
int task = b.nextInt();
if (task == 1){
admin.viewCarsForSale();
customer.goBackCustomer();
}
else if (task == 2){
customer.maintenance();
customer.goBackCustomer();
}
else if (task == 3){
customer.viewScheduledAppointments();
customer.goBackCustomer();
}
else if (task == 4){
Main.goBackToMainMenu();
}
else{
Main.goBackToMainMenu();
}
}
else {
Main.goBackToMainMenu();
}
}
}