-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCustomer.java
More file actions
118 lines (112 loc) · 4.51 KB
/
Customer.java
File metadata and controls
118 lines (112 loc) · 4.51 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
package user;
import billing.*;
import java.awt.*;
import java.io.*;
import java.util.Objects;
import java.util.Scanner;
public class Customer extends user{
private final Bill invoice = new Bill();
public int login() throws IOException {
int cnt=0;
String us,pass;
File admin = new File("database.txt");
Scanner fileRead = new Scanner(admin);
while(fileRead.hasNext())
{
us = fileRead.next();
pass = fileRead.next();
if(Objects.equals(us, accessUsername()) && Objects.equals(pass, accessPassword()))
{
System.out.println("Login successful.\nHello "+us);
cnt=1;
String names,num,email;
File open = new File("contact.txt");
Scanner openRead = new Scanner(open);
File current = new File("current_user.txt");
FileWriter current_write = new FileWriter(current);
while(openRead.hasNext())
{
names = openRead.next();
num = openRead.next();
email = openRead.next();
if(Objects.equals(names, accessUsername()))
{
System.out.println("Phone number : " + num);
System.out.println("Email : " + email);
current_write.write(names+" "+num+" "+email);
current_write.close();
break;
}
}
openRead.close();
break;
}
else if(Objects.equals(us, accessUsername()))
{
cnt=-1;
break;
}
}
fileRead.close();
if(cnt==-1)
{
Toolkit.getDefaultToolkit().beep();
System.out.println("Sorry :(");
System.out.println("Password is incorrect\nLogin Failed.");
return 0;
}
else if(cnt==0)
{
Toolkit.getDefaultToolkit().beep();
System.out.println("User could not be found.\nTry again with correct credentials or register as a new user");
return 0;
}
return 1;
}
public int signup() throws IOException {
String us;
File database = new File("database.txt");
Scanner databaseRead = new Scanner(database);
Scanner sc = new Scanner(System.in);
while(databaseRead.hasNext())
{
us = databaseRead.next();
databaseRead.next();
if(Objects.equals(us, accessUsername()))
{
System.out.println("Username already taken");
System.out.println("Try again with a different username...");
return 0;
}
}
databaseRead.close();
File data = new File("database.txt");
FileWriter data_write = new FileWriter(data,true);
data_write.write(accessUsername()+" "+accessPassword()+" "+'\n');
data_write.close();
System.out.println("ENTER YOUR PHONE NUMBER : ");
String number;
number = sc.nextLine();
System.out.println("ENTER EMAIL ADDRESS : ");
String email;
email = sc.nextLine();
String name=accessUsername();
File contact = new File("contact.txt");
FileWriter UpdateContact = new FileWriter(contact, true);
UpdateContact.write(name+" "+number+" "+email+'\n');
UpdateContact.close();
File current = new File("current_user.txt");
FileWriter Current_write = new FileWriter(current); //removed append=true
Current_write.write(name+" "+number+" "+email);
Current_write.close();
System.out.println("Successfully registered :)\nContinue shopping");
return 1;
}
public void show_invoice()
{
invoice.show_bill();
}
public void show_the_cart_total(){
invoice.show_cart_total();
}
}