-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAdmin.java
More file actions
111 lines (104 loc) · 3.52 KB
/
Admin.java
File metadata and controls
111 lines (104 loc) · 3.52 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
package user;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Objects;
import java.util.Scanner;
public class Admin extends user {
public int login()
{
int cnt=0;
String us,pass;
File admin = new File("admin.txt");
Scanner fileRead = null;
try {
fileRead = new Scanner(admin);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while(true) {
assert fileRead != null;
if (!fileRead.hasNext()) break;
us = fileRead.next();
pass = fileRead.next();
if(Objects.equals(us, accessUsername()) && Objects.equals(pass, accessPassword())) {
System.out.println("Hello Sir");
System.out.println("What privileges would you like ?");
fileRead.close();
cnt=1;
break;
}
}
if(cnt==0)
{
System.out.println("Sorry incorrect user-name or access_password()");
return 0;
}
return 1;
}
public void privileges() throws IOException {
System.out.println("Press 1 for checking total income till now");
System.out.println("Press 2 for checking total income on a each product available");
System.out.println("Press 3 to see user feedback");
System.out.println("Press 4 to exit");
int ch;
Scanner sc = new Scanner(System.in);
ch = sc.nextInt();
if(ch==1)
{
total_inc();
}
else if(ch==2)
{
total_on_each();
}
else if(ch==3)
{
show_user_feedback();
}
else if(ch==4)
{
System.out.println("Have a great day ahead :)");
System.exit(1);
}
else
{
System.out.println("Wrong option detected\nTry Again....");
privileges();
}
System.out.println("Press 1 to choose again and q to quit");
char ci;
ci = sc.next().charAt(0);
if(ci=='1')
{
privileges();
}
else
{
System.out.println("Have a great day ahead :)");
System.exit(1);
}
}
public void total_inc() throws IOException {
double total;
File income = new File("total_income.txt");
Scanner fileRead = new Scanner(income);
total = fileRead.nextDouble();
System.out.println("Your total income till now is : Rs. "+total);
fileRead.close();
}
public void total_on_each(){
System.out.println("This feature will be added soon :p");
}
public void show_user_feedback() throws IOException {
File admin = new File("feedback.txt");
Scanner fileRead = new Scanner(admin);
int i=1;
while(fileRead.hasNext())
{
System.out.println(i+". "+ fileRead.nextLine());
i++;
}
fileRead.close();
}
}