- Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSelectionMethod.java
More file actions
Latest commit
152 lines (141 loc) · 6.22 KB
/
Copy pathSelectionMethod.java
File metadata and controls
152 lines (141 loc) · 6.22 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
importjava.util.*;
importjava.io.*;
publicclassSelectionMethod{
staticScannerinput = newScanner(System.in);
staticintoption;
staticjava.util.Datedate=newjava.util.Date();
staticStringname;
publicstaticvoidchooseMethod(StringregNumber) throwsException{
intamount = 2000;
FoodSelectionfoodSelectionObj = newFoodSelection();//Create an object to acces class FoodSelection
DrinkSelectiondrinkobj = newDrinkSelection();//Create an object to acces class DrinkSelection
while(true){
System.out.println("1.Food\n2.Drinks\n3.bill Generate\n4. Previous Menu.\n5.Exit\n");
try {
System.out.print("Enter Your Choice: ");
option = input.nextInt();
System.out.println();
if(option == 1){
foodSelectionObj.food(regNumber);//Method from class FoodSelection is called here .
System.out.println("********************************************");
// break;
}
elseif(option == 2){
drinkobj.myDrink(regNumber);//Method from class DrinkSelection is called here .
System.out.println("********************************************");
// break;
}
elseif(option == 3){
Filefile = newFile("students_data/"+ regNumber +".txt");
try{
Scannersc = newScanner(file);
String[] line = sc.nextLine().split(":");
name = line[1];
}
catch(Exceptione){
System.out.print("Error occured!");
}
MyFastFoodfastfoodobject = newMyFastFood();//Create an object to call methods from class MyFastFood
intnum = fastfoodobject.FastfoodBill();//method FastfoodBill is caled and its value is stored in num variable
MyDesiFooddesifoodobject = newMyDesiFood();//Create an object to call methods from class MyDesiFood
intnum2 = desifoodobject.DesifoodBill();//method DesifoodBill is caled and its value is stored in num2 variable
MySoftDrinkssoftDrinkobject = newMySoftDrinks();//Create an object to call methods from class MySoftDrinks
intnum3 = softDrinkobject.SoftDrinkbill();//method SoftDrinkbill is caled and its value is stored in num3 variable
MyCoffeecoffeeobject = newMyCoffee();//Create an object to call methods from class MyCoffee
intnum4 =coffeeobject.CoffeeBill();//method CoffeeBill is caled and its value is stored in num4 variable
MyJuiceOrPlantDrinkjuiceOrPlantDrinkobject = newMyJuiceOrPlantDrink();//Create an object to call methods from class MyJuiceOrPlantDrink
intnum5 = juiceOrPlantDrinkobject.JuiceORPlantbill();//method JuiceORPlantbill is caled and its value is stored in num5 variable
intTotalAmount= num+num2+num3+num4+num5;
if(amount>=TotalAmount&& TotalAmount !=0){// check the amount in student account is enough to pay Total amount.
System.out.println("\n\n\n");
System.out.println("\t\t\t-----------------------------------");
System.out.println("\t\t\tDate: "+date);
System.out.println("\t\t\tName: "+name);
System.out.println("\t\t\tStudent ID: "+regNumber);
System.out.println("\t\t\t---------Thanks For Coming---------");
System.out.println("\t\t\t-----------Your Bill Is------------\n");
Filefile2 = newFile("cafe/CafeBills/BillFastfood.txt");
ScannermyReader = newScanner(file2);
intcount = 0;//to create size of array
while(myReader.hasNextLine()) {
myReader.nextLine();
count+=1;
}
Scannerreader = newScanner(file2);
String[] array = newString[count];
intindex = 0;
//Read the data in file as well as input the data in the String Array.
while (reader.hasNextLine()){
array[index] = reader.nextLine();//read data from file.
index++;
}
System.out.println("\t\t\tItems Quantity Prices\n");
for (inti = 0 ;i<array.length ;i++ ) {
System.out.print("\t\t\t"+array[i]+"\n");
}
System.out.printf("\t\t\tTotal Bill %d \n",(num+num2+num3+num4+num5));//Total Bill is formed here.
System.out.println("\t\t\t---------------------------------------");
System.out.println("\t\t\t---------------------------------------");
System.out.println("\t\t\t---------------------------------------");
System.out.println();
try{
Filefile1 = newFile("cafe/CafeBills/FinalBills/"+ regNumber +".txt");
booleanvalue = file1.createNewFile();
FileWriterbillObj = newFileWriter(file1,true);
billObj.write("Date: "+date+"\n");
billObj.write("-----------------------------------\n");
billObj.write("Name : "+ name +"\n");
billObj.write("Student ID : "+ regNumber +"\n");
billObj.write("-----------------------------------\n");
billObj.write("---------Thanks For Coming---------\n");
billObj.write("-----------Your Bill Is------------\n");
billObj.write("\t\t\tItems Quantity Prices\n");
for (inti = 0 ;i<array.length ;i++ ) {
billObj.write(""+array[i]+"\n");//Write the data
}
billObj.write("Total Bill "+TotalAmount+"\n");
billObj.write("-----------------------------------\n");
billObj.write("-----------------------------------\n\n\n");
billObj.close();
}
catch(Exceptione){
System.out.println("invalid");
}
}
else{
if (TotalAmount==0) {
System.out.println("Please Buy Something First");
// break;
// return amount;
}
elseif(TotalAmount!=0){
System.out.println("Sir, You don't have enough Account Balance");
}
}
}
elseif(option == 4){
Filefile3 = newFile("cafe/CafeBills/BillFastfood.txt");
PrintWriterwriter = newPrintWriter(file3);
writer.print("");
writer.close();
CafeManagement.manage(regNumber);
}
elseif(option ==5){//If user does not want to buy anything
System.out.println("********************************************");
Filefile2 = newFile("cafe/CafeBills/BillFastfood.txt");
PrintWriterwriter = newPrintWriter(file2);
writer.print("");
writer.close();
System.exit(0);
}
else{
System.out.println("Please select correct option ");
}
} catch(Exceptione){
System.out.println("Invalid Inputs");
input.nextLine();
continue;
}
}
}
}