-
Notifications
You must be signed in to change notification settings - Fork 2
/
Bill.java
158 lines (155 loc) · 4.84 KB
/
Bill.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
package billing;
import product.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Bill
{
public void show_bill()
{
String us = "", mob ="", em="";
File myFile = new File("current_user.txt");
try
{
Scanner sc = new Scanner(myFile);
int f=0;
while(f<=2 && sc.hasNext())
{
if(f==0)
{
us = sc.next();
}
else if(f==1)
{
mob = sc.next();
}
else if(f==2)
{
em = sc.next();
}
f++;
}
f=1;
System.out.println("Username : "+us);
System.out.println("Mobile No: "+mob);
System.out.println("Email Id : "+em);
System.out.println();
String prod_type;
String prod;
String ids = null;
String total_price;
String quantity;
while(sc.hasNext())
{
if(f%5==1)
{
ids = sc.next();
System.out.println("Id : "+ids);
}
else if(f%5==2)
{
prod_type = sc.next();
System.out.println("Product Type : "+prod_type);
}
else if(f%5==3)
{
prod = sc.next();
System.out.println("Product : "+prod);
}
else if(f%5==4)
{
quantity = sc.next();
System.out.println("Quantity : "+quantity);
}
else if(f%5==0)
{
total_price = sc.next();
System.out.println("Total Price : Rs"+total_price);
System.out.println();
}
f++;
}
System.out.println("Total number of items bought : "+ids);
System.out.println();
show_cart_total();
System.out.println();
char choice;
while(true)
{
System.out.println("Would you like to make payment?");
System.out.println("Press y for yes or r to return to catalogue or q to quit");
Scanner sc1 = new Scanner(System.in);
choice = sc1.next().charAt(0);
if(choice == 'y' || choice == 'Y')
{
proceed_to_pay();
break;
}
else if(choice == 'q' || choice == 'Q')
{
System.out.println("You have been logged out!!");
System.out.println("Have a nice day :)");
System.exit(0);
}
else if(choice == 'r' || choice =='R')
{
Catalogue random = new Catalogue() ;
random.showCatalogue();
break;
}
else
{
System.out.print("Invalid Choice....Try Again");
}
}
}
catch (FileNotFoundException e)
{
System.out.println("Err.....cannot find records!!!");
System.out.println("Please try again after some time!");
}
}
public void proceed_to_pay()
{
Payment pay = new Payment();
System.out.println();
pay.verify_user();
System.out.println();
pay.get_payment_mode();
System.out.println();
pay.display_payment_details();
System.out.println();
}
public void show_cart_total()
{
File myFile = new File("current_user.txt");
try
{
Scanner sc = new Scanner(myFile);
double total_price;
double cart_total=0;
String temp;
if(sc.hasNextLine())
{
sc.nextLine();
}
int f = 1;
while(sc.hasNext())
{
temp = sc.next();
if(f%5==0)
{
total_price = Double.parseDouble(temp);
cart_total += total_price;
}
f++;
}
System.out.println("Your cart total is : Rs "+cart_total);
}
catch (FileNotFoundException e)
{
System.out.println("Err.....cannot find records!!!");
System.out.println("Please try again after some time!");
}
}
}