/
cashier.java
161 lines (125 loc) · 4.62 KB
/
cashier.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
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
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
class cashier_opt{
DoubleLinkedList items = new DoubleLinkedList();
ArrayList<String> quantity = new ArrayList<String>();
ArrayList<Integer> price = new ArrayList<Integer>();
int bill_amt = 0;
void bill_generate(){
Scanner sc = new Scanner(System.in);
try{
File f1 = new File("order.csv");
Scanner r1 = new Scanner(f1);
Stack lines = new Stack(100);
while (r1.hasNextLine()){
lines.push(r1.nextLine());
}
for (int i = 0; i < lines.getSize(); i++) {
String line = lines.pop();
if (line.contains(",")) {
String[] det = line.split(",");
int q = Integer.parseInt(det[1]);
int p = Integer.parseInt(det[2]);
items.add(det[0]);
quantity.add(det[1]);
price.add(q * p);
bill_amt += q * p;
}
else if (line.contains("NEW")) {
break;
}
r1.close();
}
System.out.println("Bill processing successful");
}
catch (FileNotFoundException e){
System.out.println("Something went wrong...");
}
try{
File f2 = new File("cash_finance.csv");
if(!f2.exists()){
f2.createNewFile();
}
FileWriter fw = new FileWriter(f2, true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
pw.println("NEW");
for (int i = 0; i < items.size(); i++){
pw.println(items.get(i) + "," + quantity.get(i) + "," + price.get(i));
}
pw.println(bill_amt);
pw.close();
}
catch (IOException e){
System.out.println("Something went wrong...");
}
}
void bill_display(){
System.out.println("----------------------------------------");
System.out.println(" Bill");
System.out.println("----------------------------------------");
try{
File f1 = new File("cash_finance.csv");
Scanner r1 = new Scanner(f1);
Stack lines = new Stack(100);
while (r1.hasNextLine()){
lines.push(r1.nextLine());
}
for (int i = 0; i < lines.getSize(); i++) {
String line = lines.pop();
if (line.contains(",")) {
String[] det = line.split(",");
System.out.println(i + ". " + det[0] + "\n\tQuantity:-" + det[1] + "\n\tPrice:- Rs." + det[2] + "\n");
}
else if (line.contains("NEW")) {
break;
}
else{
System.out.println("Total Amount: " + line + "\n");
}
r1.close();
}
r1.close();
}
catch (FileNotFoundException e){
System.out.println("Something went wrong...");
}
items.clear();
quantity.clear();
price.clear();
bill_amt = 0;
}
void disp_fin(){
try{
File f = new File("cash_finance.csv");
Scanner r = new Scanner(f);
System.out.println("----------------------------------------");
System.out.println(" Cashier Finance");
System.out.println("----------------------------------------");
int c = 1;
while (r.hasNextLine()){
String line = r.nextLine();
if (line.contains(",")) {
String[] det = line.split(",");
System.out.println(c + ". " + det[0] + "\n\tQuantity:-" + det[1] + "\n\tPrice:- Rs." + det[2] + "\n");
c++;
}
else if (line.contains("NEW")) {
continue;
}
else{
System.out.println("\tTotal Amount: " + line + "\n");
}
}
r.close();
}
catch (FileNotFoundException e){
System.out.println("Something went wrong...");
}
}
}