getting total amount in my cashiering system - java

i have a cashiering system and here's my codes:
import javax.swing.*;
import java.util.Scanner;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class FinalProject {
private static final int totalsundae = 0;
public static void main(String[] args) {
int totaldrinks = 0, totalfries = 0, totalburger = 0, totalsundae = 0;
FinalProject m = new FinalProject();
m.Cashiering();
}
public void Cashiering() {
String menu[] = {"Customer's Name", "Menu", "Pay", "View Order list", "Exit"};
String choice = "";
char ch;
do {
choice = (String) JOptionPane.showInputDialog(null, "Please select your order", "menu", 1, null, menu, menu[0]);
ch = choice.toLowerCase().charAt(0);
switch (ch) {
case 'c':
customer();
break;
case 'm':
menu2();
break;
case 'p':
getTotal();
break;
case 'v':
orderList();
break;
case 'e':
System.exit(0);
}
} while (!choice.equals("Close"));
}
public void customer() {
String name = (String) JOptionPane.showInputDialog("WELCOME !!!!! \n\nPLEASE ENTER YOUR NAME: ");
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt", true));
printW.println("Customer's Name " + "\n" + name);
JOptionPane.showMessageDialog(null, "Your Name successfully stored \n\n You can Order Now ");
printW.close();
} catch (Exception e) {
}
}
public int burger() {
int burger = 0, quantity = 0, totalburger = 0;
int choice;
String burgnm = "";
String menu = "\nBURGER: \n1.Regular Burger 45 \n2.Burger with cheese---->55 \n3.Burger with egg and cheese----50 \n4.Burger with ham---->60 \n5.Burger with ham and cheese---->70 ";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: " + menu));
switch (choice) {
case 1:
burger += 45;
burgnm = "Regular Burger - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 2:
burger += 55;
burgnm = "Burger with cheese - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 3:
burger += 50;
burgnm = "Burger with egg and cheese - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 4:
burger += 60;
burgnm = "Burger with ham - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 5:
burger += 70;
burgnm = "Burger with ham and cheese - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totalburger = quantity * burger;
burgnm = burgnm + totalburger + "\n";
JOptionPane.showMessageDialog(null, "Total = " + burgnm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt", true));
if (choice == 1) {
printW.println("Customer's Order " + "\n" + quantity + burgnm);
} else if (choice == 2)
printW.println("Customer's Order " + "\n" + quantity + burgnm);
else if (choice == 3)
printW.println("Customer's Order " + "\n" + quantity + burgnm);
else if (choice == 4)
printW.println("Customer's Order " + "\n" + quantity + burgnm);
else if (choice == 5)
printW.println("Customer's Order " + "\n" + quantity + burgnm);
JOptionPane.showMessageDialog(null, "Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
return totalburger;
}
public int Spaghetti() {
int choice, quantity = 0, totalspag = 0, spaghetti = 0;
String spagnm = null;
String menu = "\nSPAGHETTI: \n1.Regular spaghetti---->60 \n2.Large Spaghetti---->70";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: " + menu));
switch (choice) {
case 1:
spaghetti += 60;
spagnm = "Regular Spaghetti - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 2:
spaghetti += 70;
spagnm = "Large Spaghetti - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totalspag = quantity * spaghetti;
spagnm = spagnm + totalspag + "\n";
JOptionPane.showMessageDialog(null, "Total = " + spagnm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt", true));
if (choice == 1) {
printW.println("Customer's Order " + "\n" + quantity + spagnm);
} else if (choice == 2)
printW.println("Customer's Order " + "\n" + quantity + spagnm);
JOptionPane.showMessageDialog(null, "Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
return totalspag;
}
public int Fries() {
int choice, fries = 0, quantity = 0, totalfries = 0;
String friesnm = "";
String menu = "\nFRIES: \n1.Regular Fries ----> 35\n2.Medium Fries ----> 45 \n3.LargeFries ----> 55";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: " + menu));
switch (choice) {
case 1:
fries += 35;
friesnm = "Regular Fries - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 2:
fries += 45;
friesnm = "Medium Fries - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 3:
fries += 55;
friesnm = "Large Fries - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totalfries = quantity * fries;
friesnm = friesnm + totalfries + "\n";
JOptionPane.showMessageDialog(null, "Total = " + friesnm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt", true));
if (choice == 1) {
printW.println("Customer's Order " + "\n" + quantity + friesnm);
} else if (choice == 2)
printW.println("Customer's Order " + "\n" + quantity + friesnm);
else if (choice == 3)
printW.println("Customer's Order " + "\n" + quantity + friesnm);
JOptionPane.showMessageDialog(null, "Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
return totalfries;
}
public int Sundae() {
int choice, quantity = 0, sundae = 0, totalsun = 0;
String sundaenm = "";
String menu = "\nSUNDAE: \n1.Choco sundae ----> 28 \n2.Caramel sundae ----> 28 \n3.Strawberry sundae ----> 28";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: " + menu));
switch (choice) {
case 1:
sundae += 28;
sundaenm = " Choco Sundae -";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 2:
sundae += 28;
sundaenm = " Caramel Sundae ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 3:
sundae += 28;
sundaenm = " Strawberry Sundae - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totalsun = quantity * sundae;
sundaenm = sundaenm + totalsun + "\n";
JOptionPane.showMessageDialog(null, "Total = " + sundaenm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt", true));
if (choice == 1) {
printW.println("Costumer's Order " + "\n" + quantity + sundaenm);
} else if (choice == 2)
printW.println("Costumer's Order " + "\n" + quantity + sundaenm);
else if (choice == 3)
printW.println("Costumer's Order " + "\n" + quantity + sundaenm);
JOptionPane.showMessageDialog(null, "Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
return totalsun;
}
public int Drinks() {
int choice, quantity = 0, drinks = 0, totaldrinks = 0;
String drinksnm = "";
String menu = "\nDRINKS: \n1.Reg. Coke ----> 25 \n2.Large Coke ----> 35 \n3.Reg.Sprite ----> 28 \n4.Large Sprite ----> 38";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: " + menu));
switch (choice) {
case 1:
drinks += 25;
drinksnm = "Regular Coke - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 2:
drinks += 35;
drinksnm = "Large Coke - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 3:
drinks += 28;
drinksnm = "Regular Sprite - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
case 4:
drinksnm = "Large Sprite - ";
quantity = Integer.parseInt(JOptionPane.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totaldrinks = quantity * drinks;
drinksnm = drinksnm + totaldrinks + "\n";
JOptionPane.showMessageDialog(null, "Total = " + drinksnm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt", true));
if (choice == 1) {
printW.println("Costumer's Order " + "\n" + quantity + drinksnm);
} else if (choice == 2)
printW.println("Costumer's Order " + "\n" + quantity + drinksnm);
else if (choice == 3)
printW.println("Costumer's Order " + "\n" + quantity + drinksnm);
else if (choice == 4)
printW.println("Costumer's Order " + "\n" + quantity + drinksnm);
JOptionPane.showMessageDialog(null, "Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
return totaldrinks;
}
public void orderList() {
try {
Scanner in = new Scanner(new FileReader("cash.txt"));
String all = "\nWELCOME !!!! \nCASHIERING SYSTEM\n";
while (in.hasNext()) {
all = all + in.nextLine() + "\n";
}
JOptionPane.showMessageDialog(null, new JTextArea(all));
in.close();
} catch (Exception e) {
}
}
public void getTotal() {
}
public void menu2() {
String menu[] = {"Burger", "Spaghetti", "Fries", "Ice Sundae", "Drinks", "Exit"};
String choice = "";
char ch;
int yesorno = 0;
do {
choice = (String) JOptionPane.showInputDialog(null, "Please select your order", "menu", 1, null, menu, menu[0]);
ch = choice.toLowerCase().charAt(0);
switch (ch) {
case 'b':
burger();
yesorno = Integer.parseInt(JOptionPane.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 's':
Spaghetti();
yesorno = Integer.parseInt(JOptionPane.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 'f':
Fries();
yesorno = Integer.parseInt(JOptionPane.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 'i':
Sundae();
yesorno = Integer.parseInt(JOptionPane.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 'd':
Drinks();
yesorno = Integer.parseInt(JOptionPane.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 'e':
break;
}
} while (!choice.equals("Close"));
}
}
my problem here is the total. how can i get the total of the customer's order by using a method? i'm really a beginner in java so i hope you can give some simple codes. thank you so much for your help!

Use a totalOrder variable to store the total for that session.
import javax.swing.*;
import java.util.Scanner;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class FinalProject {
private int totalOrder;
private static final int totalsundae = 0;
public static void main(String[] args) {
int totaldrinks = 0, totalfries = 0, totalburger = 0, totalsundae = 0;
FinalProject m = new FinalProject();
m.Cashiering();
}
public void Cashiering() {
String menu[] = { "Customer's Name", "Menu", "Pay", "View Order list",
"Exit" };
String choice = "";
char ch;
do {
choice = (String) JOptionPane.showInputDialog(null,
"Please select your order", "menu", 1, null, menu, menu[0]);
ch = choice.toLowerCase().charAt(0);
switch (ch) {
case 'c':
customer();
break;
case 'm':
menu2();
break;
case 'p':
getTotal();
break;
case 'v':
orderList();
break;
case 'e':
System.exit(0);
}
} while (!choice.equals("Close"));
}
public void customer() {
String name = (String) JOptionPane
.showInputDialog("WELCOME !!!!! \n\nPLEASE ENTER YOUR NAME: ");
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt",
true));
printW.println("Customer's Name " + "\n" + name);
JOptionPane.showMessageDialog(null,
"Your Name successfully stored \n\n You can Order Now ");
printW.close();
} catch (Exception e) {
}
}
public int burger() {
int burger = 0, quantity = 0, totalburger = 0;
int choice;
String burgnm = "";
String menu = "\nBURGER: \n1.Regular Burger 45 \n2.Burger with cheese---->55 \n3.Burger with egg and cheese----50 \n4.Burger with ham---->60 \n5.Burger with ham and cheese---->70 ";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: "
+ menu));
switch (choice) {
case 1:
burger += 45;
burgnm = "Regular Burger - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 2:
burger += 55;
burgnm = "Burger with cheese - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 3:
burger += 50;
burgnm = "Burger with egg and cheese - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 4:
burger += 60;
burgnm = "Burger with ham - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 5:
burger += 70;
burgnm = "Burger with ham and cheese - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totalburger = quantity * burger;
burgnm = burgnm + totalburger + "\n";
JOptionPane.showMessageDialog(null, "Total = " + burgnm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt",
true));
if (choice == 1) {
printW.println("Customer's Order " + "\n" + quantity
+ burgnm);
} else if (choice == 2)
printW.println("Customer's Order " + "\n" + quantity
+ burgnm);
else if (choice == 3)
printW.println("Customer's Order " + "\n" + quantity
+ burgnm);
else if (choice == 4)
printW.println("Customer's Order " + "\n" + quantity
+ burgnm);
else if (choice == 5)
printW.println("Customer's Order " + "\n" + quantity
+ burgnm);
JOptionPane.showMessageDialog(null,
"Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
totalOrder = totalOrder + totalburger;
return totalburger;
}
public int Spaghetti() {
int choice, quantity = 0, totalspag = 0, spaghetti = 0;
String spagnm = null;
String menu = "\nSPAGHETTI: \n1.Regular spaghetti---->60 \n2.Large Spaghetti---->70";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: "
+ menu));
switch (choice) {
case 1:
spaghetti += 60;
spagnm = "Regular Spaghetti - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 2:
spaghetti += 70;
spagnm = "Large Spaghetti - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totalspag = quantity * spaghetti;
spagnm = spagnm + totalspag + "\n";
JOptionPane.showMessageDialog(null, "Total = " + spagnm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt",
true));
if (choice == 1) {
printW.println("Customer's Order " + "\n" + quantity
+ spagnm);
} else if (choice == 2)
printW.println("Customer's Order " + "\n" + quantity
+ spagnm);
JOptionPane.showMessageDialog(null,
"Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
totalOrder = totalOrder + totalspag;
return totalspag;
}
public int Fries() {
int choice, fries = 0, quantity = 0, totalfries = 0;
String friesnm = "";
String menu = "\nFRIES: \n1.Regular Fries ----> 35\n2.Medium Fries ----> 45 \n3.LargeFries ----> 55";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: "
+ menu));
switch (choice) {
case 1:
fries += 35;
friesnm = "Regular Fries - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 2:
fries += 45;
friesnm = "Medium Fries - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 3:
fries += 55;
friesnm = "Large Fries - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totalfries = quantity * fries;
friesnm = friesnm + totalfries + "\n";
JOptionPane.showMessageDialog(null, "Total = " + friesnm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt",
true));
if (choice == 1) {
printW.println("Customer's Order " + "\n" + quantity
+ friesnm);
} else if (choice == 2)
printW.println("Customer's Order " + "\n" + quantity
+ friesnm);
else if (choice == 3)
printW.println("Customer's Order " + "\n" + quantity
+ friesnm);
JOptionPane.showMessageDialog(null,
"Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
totalOrder = totalOrder + totalfries;
return totalfries;
}
public int Sundae() {
int choice, quantity = 0, sundae = 0, totalsun = 0;
String sundaenm = "";
String menu = "\nSUNDAE: \n1.Choco sundae ----> 28 \n2.Caramel sundae ----> 28 \n3.Strawberry sundae ----> 28";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: "
+ menu));
switch (choice) {
case 1:
sundae += 28;
sundaenm = " Choco Sundae -";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 2:
sundae += 28;
sundaenm = " Caramel Sundae ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 3:
sundae += 28;
sundaenm = " Strawberry Sundae - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totalsun = quantity * sundae;
sundaenm = sundaenm + totalsun + "\n";
JOptionPane.showMessageDialog(null, "Total = " + sundaenm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt",
true));
if (choice == 1) {
printW.println("Costumer's Order " + "\n" + quantity
+ sundaenm);
} else if (choice == 2)
printW.println("Costumer's Order " + "\n" + quantity
+ sundaenm);
else if (choice == 3)
printW.println("Costumer's Order " + "\n" + quantity
+ sundaenm);
JOptionPane.showMessageDialog(null,
"Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
totalOrder = totalOrder + totalsun;
return totalsun;
}
public int Drinks() {
int choice, quantity = 0, drinks = 0, totaldrinks = 0;
String drinksnm = "";
String menu = "\nDRINKS: \n1.Reg. Coke ----> 25 \n2.Large Coke ----> 35 \n3.Reg.Sprite ----> 28 \n4.Large Sprite ----> 38";
choice = Integer.parseInt(JOptionPane.showInputDialog("Please select: "
+ menu));
switch (choice) {
case 1:
drinks += 25;
drinksnm = "Regular Coke - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 2:
drinks += 35;
drinksnm = "Large Coke - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 3:
drinks += 28;
drinksnm = "Regular Sprite - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
case 4:
drinksnm = "Large Sprite - ";
quantity = Integer.parseInt(JOptionPane
.showInputDialog("How many do you want??? "));
break;
default:
JOptionPane.showMessageDialog(null, "INVALID");
}
if (quantity < 0) {
JOptionPane.showMessageDialog(null, "INVALID");
} else {
totaldrinks = quantity * drinks;
drinksnm = drinksnm + totaldrinks + "\n";
JOptionPane.showMessageDialog(null, "Total = " + drinksnm);
try {
PrintWriter printW = new PrintWriter(new FileWriter("cash.txt",
true));
if (choice == 1) {
printW.println("Costumer's Order " + "\n" + quantity
+ drinksnm);
} else if (choice == 2)
printW.println("Costumer's Order " + "\n" + quantity
+ drinksnm);
else if (choice == 3)
printW.println("Costumer's Order " + "\n" + quantity
+ drinksnm);
else if (choice == 4)
printW.println("Costumer's Order " + "\n" + quantity
+ drinksnm);
JOptionPane.showMessageDialog(null,
"Record successfully stored ");
printW.close();
} catch (Exception e) {
}
}
totalOrder = totalOrder + totaldrinks;
return totaldrinks;
}
public void orderList() {
try {
Scanner in = new Scanner(new FileReader("cash.txt"));
String all = "\nWELCOME !!!! \nCASHIERING SYSTEM\n";
while (in.hasNext()) {
all = all + in.nextLine() + "\n";
}
JOptionPane.showMessageDialog(null, new JTextArea(all));
in.close();
} catch (Exception e) {
}
}
public void getTotal() {
JOptionPane.showMessageDialog(null, "Order Total\n"+ totalOrder + "");
}
public void menu2() {
String menu[] = { "Burger", "Spaghetti", "Fries", "Ice Sundae",
"Drinks", "Exit" };
String choice = "";
char ch;
int yesorno = 0;
do {
choice = (String) JOptionPane.showInputDialog(null,
"Please select your order", "menu", 1, null, menu, menu[0]);
ch = choice.toLowerCase().charAt(0);
switch (ch) {
case 'b':
burger();
yesorno = Integer
.parseInt(JOptionPane
.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 's':
Spaghetti();
yesorno = Integer
.parseInt(JOptionPane
.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 'f':
Fries();
yesorno = Integer
.parseInt(JOptionPane
.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 'i':
Sundae();
yesorno = Integer
.parseInt(JOptionPane
.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 'd':
Drinks();
yesorno = Integer
.parseInt(JOptionPane
.showInputDialog("Do you still have any order?? \n 1.Yes \n2.No"));
if (yesorno == 1) {
menu2();
} else {
Cashiering();
}
break;
case 'e':
break;
}
} while (!choice.equals("Close"));
}
}

Related

How do I initialize a variable in an if else program that combines three choices?

I'm writing a party planner program for a question for class.
I can't initialize my three choices of entertainment, decorations, and food.
Eclipse tells me that I should set all these values to 0. I have to stick to these if else statements because that's what we have learned so far.
Here is my code:
import java.util.Scanner;
public class PartyPlanner {
public static void main(String[] args) {
// TODO Auto-generated method stub
int entertainment;
int decorations;
int food;
int budget = entertainment + decorations + food;
Scanner keyboard = new Scanner(System.in);
System.out.println("For your choices, please type"
+ " in what is contained in the brackets."
+ " We will do the calculations for you.");
System.out.println("Choose entertainment:"
+ " [band] for $400 or " + "[DJ] for $150");
String choice1 = keyboard.nextLine();
if (choice1 == "DJ")
{
entertainment = 400;
}
else if (choice1 == "band")
{
entertainment = 150;
}
System.out.println("Where would you like to buy "
+ "decorations? [school] for $100 or [your own] for $250 ?");
String choice2 = keyboard.nextLine();
if (choice2 == "school")
{
decorations = 100;
}
else if (choice2 == "your own")
{
decorations = 250;
}
System.out.println("Would you like to purchase"
+ " [pizza] for $200 or [sub sandwiches]"
+ " for $250 or [appetizers] for $150?");
String choice3 = keyboard.nextLine();
if (choice3 == "pizza")
{
food = 200;
}
else if (choice3 == "sub sandwiches")
{
food = 250;
}
else if (choice3 == "appetizers")
{
food = 150;
}
System.out.println("You have chosen: " + choice1 +
" and " + choice2 + " and " + choice3);
System.out.println("The total cost of this party"
+ " comes out to:" + budget);
}
}
The problem is
The local variable entertainment, decorations, and food may have not been initalized.
First , you have to make the sum at the end of the code because at first the variables are not initialized yet , and secondly you can assign a value of zero if no choice have been made , like this :
public class PartyPlanner {
public static void main(String[] args) {
// TODO Auto-generated method stub
int entertainment;
int decorations;
int food;
Scanner keyboard = new Scanner(System.in);
System.out.println("For your choices, please type"
+ " in what is contained in the brackets."
+ " We will do the calculations for you.");
System.out.println("Choose entertainment:"
+ " [band] for $400 or " + "[DJ] for $150");
String choice1 = keyboard.nextLine();
if (choice1 == "DJ")
{
entertainment = 400;
}
else if (choice1 == "band")
{
entertainment = 150;
}
else { entertainment = 0; }
System.out.println("Where would you like to buy "
+ "decorations? [school] for $100 or [your own] for $250 ?");
String choice2 = keyboard.nextLine();
if (choice2 == "school")
{
decorations = 100;
}
else if (choice2 == "your own")
{
decorations = 250;
}
else { decorations = 0; }
System.out.println("Would you like to purchase"
+ " [pizza] for $200 or [sub sandwiches]"
+ " for $250 or [appetizers] for $150?");
String choice3 = keyboard.nextLine();
if (choice3 == "pizza")
{
food = 200;
}
else if (choice3 == "sub sandwiches")
{
food = 250;
}
else if (choice3 == "appetizers")
{
food = 150;
}
else { food = 0 ; }
int budget = entertainment + decorations + food;
System.out.println("You have chosen: " + choice1 +
" and " + choice2 + " and " + choice3);
System.out.println("The total cost of this party"
+ " comes out to:" + budget);
}
}

Switch statements gets ignored after my if-else statements

//Scanner
Scanner scan = new Scanner(System.in);
//Variables
double bmi; // Body Mass Index
double weight; // Weight in kilograms
double height; // Height in meters
String[] classification = {"Underweight", "Normal", "Overweight", "Obese"};
System.out.print("Your weight in KG \n");
weight = scan.nextDouble();
System.out.print("Enter height in meters: \n");
height = scan.nextDouble();
bmi = weight / (height * height);
if (bmi < 18.5) {
System.out.print("You're " + classification[0] + "\n");
} else if (bmi < 25) {
System.out.print("You're " + classification[1] + "\n");
} else if (bmi < 30) {
System.out.print("You're " + classification[2] + "\n");
} else {
System.out.print("You're " + classification[3] + "\n");
}
switch (Arrays.toString(classification)) {
case "Underweight":
System.out.println("Underweight");
break;
case "Normal":
System.out.println("Normal");
break;
case "Overweight":
System.out.println("A bit overweighted");
break;
case "Obese":
System.out.println("A bit obese");
break;
default:
System.out.println("Ok");
break;
}
}
output,, my switch statement does not work after the if-else statements. It ignores everything and jumps directly to the default in my switch. While my intentions are to follow up with some text after the if-else. So basically if my calculations show me i'm overweighted than my switch statement must now to jump to case "overweighted" and print out that piece of code.. What am I doing wrong?
The result of Arrays.toString(classification) which is [Underweight, Normal, Overweight, Obese] does not match any switch case.
The solution could be something like this:
String result = null;
if (bmi < 18.5) {
System.out.print("You're " + classification[0] + "\n");
result = classification[0];
} else if (bmi < 25) {
System.out.print("You're " + classification[1] + "\n");
result = classification[1];
} else if (bmi < 30) {
System.out.print("You're " + classification[2] + "\n");
result = classification[2];
} else {
System.out.print("You're " + classification[3] + "\n");
result = classification[3];
}
switch (result) {
case "Underweight":
System.out.println("Underweight");
break;
case "Normal":
System.out.println("Normal");
break;
case "Overweight":
System.out.println("A bit overweighted");
break;
case "Obese":
System.out.println("A bit obese");
break;
default:
System.out.println("Ok");
break;
}

In a java project I designed to simulate a dominos home , there is error where the code takes my input for size many times

import java.io.*;
class PizzaDelivery
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String pizza[] = { "MARGHERITA", "DOUBLE CHEESE MARGHERITA" , "FARM HOUSE", "DELUXE VEGGIE" , "CHEESE N' CORN" , "PEPPERONI PIZZA" , "PERI-PERI CHICKEN" , "NON VEG SUPREME" , "CHICKEN FIESTA" , "CHICKEN SAUSAGE PIZZA" };
int smallprice[] = { 195,300,285,355,235,205,300,285,355,300};
int mediumprice[] = { 245,380,325,405,285,275,380,355,405,345};
int largeprice[] = { 305,435,405,495,305,305,435,425,495,435};
String sides[] = {"GARLIC BREADTSTICKS" , "STUFFED GARLIC BREADSTICKS" , "CHOCO LAVA CAKE" ,"COCA COLA"};
int sideprice[] = { 155, 205 , 245 , 75};
String cart[] = new String[100];
int bill[] = new int[100];
int k = 0,areacode;
String cont,street,house,area;
String name;
double total=0.0;
long phno;
int f,flag,success;
public void menu() throws IOException
{
String choice;
int ch;
System.out.println("**************** WELCOME TO DOMINOS PIZZA HOME DELIVERY ******************");
System.out.println("Veg pizzas");
System.out.println("1. MARGHERITA - A hugely popular margherita, with a deliciously tangy single cheese topping");
System.out.println("2. DOUBLE CHEESE MARGHERITA - The ever popular margherita - loaded with extra cheese.....oodies of it");
System.out.println("3. FARM HOUSE - A pizza that goes ballistic on veggies! Check out this mouth watering overload of crunchy crisp capsicum, succulent mushrooms and fresh tomatoes");
System.out.println("4. DELUXE VEGGIE - For a vegetarian looking to eat the creme de la creme pizza for veggie lovers , this is it");
System.out.println("5. CHEESE N' CORN - Cheese(tons of it) and corn - what more could someone want?");
System.out.println("Non-veg pizzas");
System.out.println("6. PEPPERONI PIZZA - for all the lovers of classic non veg pizzas out there");
System.out.println("7. PERI-PERI CHICKEN - Pepper barbeque chicken and Red paprika : the perfect combination");
System.out.println("8. NON VEG SUPREME - Bite into supreme delight of black olives, Onions , grilled mushrooms , pepper bbq chicken, peri-peri chicken, grilled chicken rashers");
System.out.println("9. CHICKEN FIESTA - A fiesta of tasty chicken for the refined taste buds");
System.out.println("10. CHICKEN SAUSAGE - A classic ");
System.out.println("Sides and beverages");
System.out.println("11. GARLIC BREADSTICKS");
System.out.println("12. STUFFED GARLIC BREAD");
System.out.println("13. CHOCO LAVA CAKE");
System.out.println("14. COCA COLA(500ml)");
System.out.println("You can enter 15 to exit");
do
{
System.out.println("Enter your choice of product");
choice = br.readLine();
ch = Integer.parseInt(0 + choice.replaceAll("\\D+",""));
if(ch<=10 && ch>0)
{
switch(ch)
{
case 1:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 2:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 3:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 4:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 5:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 6:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 7:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 8:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 9:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 10:
cart[k] = pizza[ch-1];
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
}
}
else if(ch>10 && ch<=15)
{
switch(ch)
{
case 11:
cart[k] = sides[ch-11];
bill[k] = sideprice[ch-11];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 12:
cart[k] = sides[ch-11];
bill[k] = sideprice[ch-11];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 13:
cart[k] = sides[ch-11];
bill[k] = sideprice[ch-11];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 14:
cart[k] = sides[ch-11];
bill[k] = sideprice[ch-11];
System.out.println("the price is: " + bill[k]);
System.out.println("The item "+ cart[k] + " has been added to your cart");
k++;
break;
case 15: System.exit(0);
}
}
else
{
System.out.println("You have entered a number that doesn't correspond to any item");
}
System.out.println("Do you want to continue buying? \n If yes, please enter \"yes\" else enter \"no\" . If you want to exit , please enter yes and then press 15");
cont = br.readLine();
if(cont.equalsIgnoreCase("No")==true)
{
return;
}
if( cont.equalsIgnoreCase("yes")==true)
{
}
else
{
System.out.println("The input entered by you is not correct. Please enter yes or no");
cont = br.readLine();
}
}while(cont.equalsIgnoreCase("Yes"));
}
int size() throws IOException
{
int size ;
int f=0;
do
{
System.out.println("Enter the number for the size of the pizza you want (1.Small/2,Medium/3.Large):");
size = Integer.parseInt(br.readLine());
if(size>=1 && size<=3)
{
break;
}
if(size>3 && size<1)
{
System.out.println("That number doesnt correspond to a size");
System.out.println("Please enter a valid choice");
f=0;
}
}while(f==0);
return size;
}
void bill() throws IOException
{
for(int i = k-1;i>=0;i--)
total+= bill[i];
System.out.println ("\n\n********************************* BILL *****************************************");
System.out.println ("\n NAME: "+ name);
System.out.println ("\n-----------------------------------------------------------------------------------------");
System.out.println ("\nITEMS \t\t\t\t \t COST ");
System.out.println ("\n-----------------------------------------------------------------------------------------");
for(int i = 0;i<k;i++)
{
System.out.println(cart[i] + "\t \t \t \t \t" + bill[i]);
}
System.out.println("\n Total : \t \t \t \t \t \t" + total);
System.out.println("SGST: 2.5% \t \t \t \t \t " + (0.025 * total));
System.out.println("CGST: 2.5% \t \t \t \t \t " + (0.025 * total));
System.out.println("GRAND TOTAL: \t \t \t \t \t" + (1.05* total));
System.out.println ("\n************************************************************************************");
System.out.println ("\n ENTER YOUR AREA NAME ");
String area =br.readLine();
System.out.println("\n ENTER YOUR STREET NAME");
String street = br.readLine();
System.out.println("\n ENTER YOUR HOUSE NAME , FLAT NUMBER(IF ANY)");
String house = br.readLine();
System.out.println("\n ENTER YOUR KOLKATA AREA CODE WITHOUT A SPACE IN BETWEEN");
do
{
try
{
f=0;
areacode = Integer.parseInt(br.readLine());
if(areacode <= 700000 && areacode >= 700163)
{
f++;
System.out.println("Your area code is not valid");
System.out.println("Enter a valid area code");
}
}
catch(Exception e)
{
System.out.println("Your area code is not valid");
System.out.println("Enter a valid area code");
areacode = Integer.parseInt(br.readLine());
f++;
}
}while(f>0);
System.out.println ("\n PAYMENT CAN BE MADE IN THE FOLLOWING WAYS:");
System.out.println ();
System.out.println ("1. CREDIT CARD OR DEBIT CARD");
System.out.println ("2. CASH ON DELIVERY");
System.out.println ("\n\n ENTER YOUR CHOICE");
for(int f = -1;f==-1;)
{
int paychoice =Integer.parseInt(br.readLine());
switch (paychoice)
{
case 1:
System.out.println ("ENTER CREDIT/DEBIT CARD NO.:");
String ccn=br.readLine();
System.out.println ("ENTER CVV NO.:");
String cvv=br.readLine();
System.out.println("Enter the date till which the card is valid");
String date = br.readLine();
System.out.println("Enter the name on the card");
String name_card = br.readLine();
System.out.println ("\n\n CONGRATULATIONS!!!!!! THE PAYMENT HAS BEEN MADE");
f=1;
break;
case 2:
f=1;
break;
default:
System.out.println ("OOPS!!! WRONG CHOICE");
System.out.println("Enter your choice again");
f=-1;
}
}
do
{
flag=0;
System.out.println("Please enter your mobile number");
System.out.print("+91");
phno = Long.parseLong(br.readLine());
int c = 0;
for(long i = phno;i!=0;i/=10)
{
int d = (int)(phno%i);
c++;
}
if(c!=10)
{
System.out.println("The entered number is not valid. Please try again");
flag++;
}
}while(flag>0);
System.out.println("Please enter your email id");
String emailid = br.readLine();
System.out.println("Your product will be delivered within 30mins. If the delivery time is more than 30 mins , you will not have to pay anything. However,if prior information is given regarding any delay in delivery time, this rule will not be valid. Further details will be provided via SMS and email");
System.out.println (" \n\nFOR FUTHER DETAILS AND QUERIES, CONTACT us using the queries section of dominos website or at the number 033 2461 4505");
System.out.println ("\n\n****************************************************** THANK YOU ******************************************************");
System.out.println ("\n\n************************************************ !!!!! VISIT AGAIN !!!!! ***********************************************");
}
void main() throws IOException
{
do
{
System.out.println("Enter your name");
name = br.readLine();
success=0;
for(int i = 0;i<name.length();i++)
{
char ch = name.charAt(i);
if(ch==' ')
{
success++;
}
}
if(success==0)
{
System.out.println("Please enter your full name separated by a space");
}
}while(success==0);
PizzaDelivery obj = new PizzaDelivery();
obj.menu();
obj.bill();
}
}
ERROR:
Enter the size is being asked too many times for one pizza
In your main switch code, every case is running the size() method multiple times in the if statements:
if(size()==1)
bill[k] = smallprice[ch-1];
else if(size()==2)
bill[k] = mediumprice[ch-1];
else if(size()==3)
bill[k] = largeprice[ch-1];
You need to run size() once before the switch cases, and save the int value returned by it in a variable which is then checked in the if statements.
Instead of a "do-while" loop in the size function, just use a while loop and it should work.

Unable to get total amount payable [duplicate]

This question already has answers here:
Unable to get total amount
(2 answers)
Closed 4 years ago.
I have designed a program which will rerun when the user enters "y" when asked if they wish to continue. The problem I am having is once the user enters "n" the program is supposed to display the total amount payable from all ticket options purchased. I have spent a couple of weeks stuck on this problem and am unsure of what to do next. I have only included the bottom part of my code. I have also included a photo to show my problem when the program is run.
here is my code:
package cse1pgx_a2;
import java.util.Scanner;
public class CSE1PGX_A2 {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
int option, quantity, confirm;
float childTotal = 0;
float adultTotal = 0;
float seniorTotal = 0;
float finalTotal = 0;
final double childCost = 18;
final double adultCost = 36;
final double seniorCost = 32.50;
boolean continueLoop = true;
char resume;
Scanner input = new Scanner(System.in);
while (continueLoop) {
System.out.println("\t"+ "##### Welcome to Zoos Victoria #####");
System.out.println("\t" + "\t" + "MAIN MENU" + "\n");
System.out.println("\t" + "Zoo has the following ticketing options" + "\n");
System.out.println("\t" + "1 = Child (4-6 yrs)");
System.out.println("\t" + "2 = Adult (16+ yrs)");
System.out.println("\t" + "3 = Senior (60+ yrs)" + "\n");
System.out.println("Enter your option:" );
option=input.nextInt();
switch (option) {
case 1:
System.out.println("Enter total No of tickets for Child:" );
quantity=input.nextInt();
System.out.println("You are purchasing " + quantity + " child tickets at " + childCost + " each!");
System.out.println("Press 1 to confirm");
confirm=input.nextInt();
break;
case 2:
System.out.println("Enter total No of tickets for Adult:" );
quantity=input.nextInt();
System.out.println("You are purchasing " + quantity + " adult tickets at " + adultCost + " each!");
System.out.println("Press 1 to confirm");
confirm=input.nextInt();
break;
default:
System.out.println("Enter total No of tickets for Senior:" );
quantity=input.nextInt();
System.out.println("You are purchasing " + quantity + " senior tickets at " + seniorCost + " each!");
System.out.println("Press 1 to confirm");
confirm=input.nextInt();
break;
}
if (confirm !=1) {
System.out.println("Incorrect key!");
}
OUTER:
while (confirm == 1) {
switch (option) {
case 1:
childTotal=(int) ((double) quantity*childCost) ;
System.out.println("Total amount for child tickets: $" + childTotal);
break OUTER;
case 2:
adultTotal=(int) ((double) quantity*adultCost) ;
System.out.println("Total amount for adult tickets $" + adultTotal);
break OUTER;
default:
seniorTotal=(int) ((double) quantity*seniorCost);
System.out.println("Total amount for senior tickets $" + seniorTotal);
break OUTER;
}
}
System.out.println("Do you wish to continue? (Y/N) ");
resume = input.next().charAt(0);
if (resume == 'y' || resume == 'Y') {
} else {
continueLoop = false;
switch (option) {
case 1:
finalTotal=(float) ((double) childTotal+adultTotal+seniorTotal) ;
System.out.println("Total amount payable: $ " + finalTotal);
break;
default:
System.out.println("Error");
}
}
}
}
}
I have fixed issues and also updated code for better performance.
package test;
import java.util.Scanner;
public class CSE1PGX_A2 {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
final float childCost = 18;
final float adultCost = 36;
final float seniorCost = 32.50F;
boolean continueLoop = true;
Scanner input = new Scanner(System.in);
float childTotal = 0;
float adultTotal = 0;
float seniorTotal = 0;
while (continueLoop) {
int option, confirm=0;
System.out.println("\t ##### Welcome to Zoos Victoria #####");
System.out.println("\t \t MAIN MENU \n");
System.out.println("\t Zoo has the following ticketing options \n");
System.out.println("\t 1 = Child (4-6 yrs)");
System.out.println("\t 2 = Adult (16+ yrs)");
System.out.println("\t 3 = Senior (60+ yrs) \n");
System.out.println("Enter your option:");
option = input.nextInt();
switch (option) {
case 1: {
System.out.println("Enter total No of tickets for Child:");
int quantity = input.nextInt();
childTotal = quantity * childCost;
System.out.println("You are purchasing " + quantity + " child tickets at " + childCost + " each!");
System.out.println("Press 1 to confirm");
confirm = input.nextInt();
if (confirm == 1) {
System.out.println("Total amount for child tickets: $" + childTotal);
}
break;
}
case 2: {
System.out.println("Enter total No of tickets for Adult:");
int quantity = input.nextInt();
adultTotal = quantity * adultCost ;
System.out.println("You are purchasing " + quantity + " adult tickets at " + adultCost + " each!");
System.out.println("Press 1 to confirm");
confirm = input.nextInt();
if (confirm == 1) {
System.out.println("Total amount for adult tickets $" + adultTotal);
}
break;
}
case 3: {
System.out.println("Enter total No of tickets for Senior:");
int quantity = input.nextInt();
seniorTotal = quantity * seniorCost ;
System.out.println("You are purchasing " + quantity + " senior tickets at " + seniorCost + " each!");
System.out.println("Press 1 to confirm");
confirm = input.nextInt();
if (confirm == 1) {
System.out.println("Total amount for senior tickets $" + seniorTotal);
}
break;
}
}
if (confirm != 1) {
System.out.println("Incorrect key!");
}
System.out.println("Do you wish to continue? (Y/N) ");
char resume = input.next().charAt(0);
if (resume != 'y' && resume != 'Y') {
continueLoop = false;
System.out.println("Total amount for child tickets: $" + childTotal);
System.out.println("Total amount for senior tickets $" + seniorTotal);
System.out.println("Total amount for adult tickets $" + adultTotal);
float finalTotal = childTotal + adultTotal + seniorTotal ;
System.out.println("Total amount payable: $ " + finalTotal);
}
}
}
}
Try this code. I hope it helps.
public static void main(String[] args) {
int option, quantity, confirm; //minor change
float childTotal = 0;
float adultTotal = 0;
float seniorTotal = 0;
float finalTotal = 0; //minor change
final double childCost = 18;
final double adultCost = 36;
final double seniorCost = 32.50;
boolean continueLoop = true;
char resume;
System.out.println("Do you wish to continue? (Y/N) ");
resume = input.next().charAt(0);
if (resume == 'y' || resume == 'Y') {
}else{
continueLoop = false;
switch (option) {
case 1:
finalTotal+=(double) quantity*childTotal ; //minor change
System.out.println("Total amount payable: $" + childTotal);
break;
case 2:
finalTotal+=(double) quantity*adultTotal ; //minor change
System.out.println("Total amount payable $" + adultTotal);
break;
default:
finalTotal+=(double) quantity*seniorTotal; //minor change
System.out.println("Total amount payable $" + seniorTotal);
break;
}
}
}
}
}
I wished to play and did not fully understand the problem...so i developed from scratch the application. Suryakant was faster so please accept his answer (if it solves your problem). I simply post this here since i worked on it :-)
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
boolean continueLoop = true;
Map<TicketType, Integer> purchases=new HashMap<>();
do {
TicketType type = printMenu(scan);
System.out.println("Enter number of tickets for " + type.label);
int quantity = scan.nextInt();
System.out.println("You are purchasing "+quantity + " "+ type.label+ " ticket at "+type.cost+" each. " +
"Press 1 to confirm?");
int confirm= scan.nextInt();
if (confirm!=1) continue;
if (purchases.containsKey(type)){
purchases.put(type,purchases.get(type)+quantity);
System.out.println("You now have " +purchases.get(type) +" "+type.label +" tickets in total");
}else {
purchases.put(type,quantity);
}
System.out.println("You have added " +quantity +" "+type.label +" tickets in your basket.");
System.out.println("Do you wish to continue (Y|N)?");
String resume=scan.next();
if (resume.startsWith("Y") || resume.startsWith("y")){
continueLoop=true;
}else {
continueLoop=false;
}
}while (continueLoop);
System.out.println("Purchases");
long total=0;
for (Map.Entry<TicketType, Integer> ticketTypeIntegerEntry : purchases.entrySet()) {
System.out.println(ticketTypeIntegerEntry.getKey().label+"("+ticketTypeIntegerEntry.getValue()+")");
total+=ticketTypeIntegerEntry.getKey().cost*ticketTypeIntegerEntry.getValue();
}
System.out.println("Total payable ammount: "+total);
}
private static TicketType printMenu(Scanner scan) {
System.out.println("Welcome");
TicketType type;
int k = -1;
do {
for (TicketType ticketType : TicketType.values()) {
System.out.println(ticketType.id + ". for " + ticketType.label);
}
System.out.println("Enter your option");
k = scan.nextInt();
} while ((type=TicketType.valuefromId(k))==null);
return type;
}
private enum TicketType {
CHILD(1, "Child", 18D),
ADULT(2, "Adult", 36D),
SENIOR(3, "Senior", 18.5D);
int id;
String label;
double cost;
private static Map<Integer,TicketType> map=new HashMap<Integer,TicketType>();
static {
for (TicketType ticketType : TicketType.values()) {
map.put(ticketType.id,ticketType);
}
}
TicketType(int id, String label, double cost) {
this.id = id;
this.label = label;
this.cost=cost;
}
public static TicketType valuefromId(int id){
return map.get(id);
}
}
}
improvements are in reading.. i would check first if what i read is character or not..

unreachable statement switch

I have a POS program that is not working it says switch(food) unreachable statement
import javax.swing.*;
import java.awt.*;
public class sari{
public static void One()
{
int choice=0,food=0,c=0,con,x=1,y=1,z=1,q=1,trans=0,price=0 ,qty,gtotal=0,ptotal=0,pay,change,total=0,ord;
String order="",bibilhin="",transaction="",A;
ImageIcon welcome = new ImageIcon("welcome.jpg");
ImageIcon chip = new ImageIcon("chip.jpg");
ImageIcon rc = new ImageIcon("rc.jpg");
ImageIcon stick = new ImageIcon("stick.jpg");
ImageIcon pancit = new ImageIcon("pancit.jpg");
ImageIcon jampong = new ImageIcon("jampong.jpg");
ImageIcon chups = new ImageIcon("chups.jpg");
ImageIcon egg = new ImageIcon("egg.jpg");
A=JOptionPane.showInputDialog("Enter your name:"); ImageIcon hansel = new ImageIcon("hansel.jpg");
JOptionPane.showMessageDialog(null,"Sir/Ma`am \n "+A+"\n Welcome\n to Mang Inasal\n Please Choose The\n product you want to buy","Welcome" ,JOptionPane.PLAIN_MESSAGE,welcome);
while(x==1)
{
c=Integer.parseInt(JOptionPane.showInputDialog(" Categories" + "\n" +"[1] Drinks" + "\n" + "[2] Foods"));
if(c==1)
{choice=Integer.parseInt(JOptionPane.showInputDialog("DRINKS" +"\n"
+ "[1] Lemonade" + "\n"
+ "[2] Coca Cola" + "\n"
+ "[3] Sprite" + "\n"
+ "[4] Mountain Dew" + "\n"
+ "[5] Pepsi" + "\n"
+ "[6] Cofee" +"\n"
+ "[7] Hot Choco" + "\n"
+ "[8] Nestie Iced Tea" +"\n"
+ "[9] Exit" +"\n"
+ "Enter Your Choice:"));
if(c==2)
food=Integer.parseInt(JOptionPane.showInputDialog("Food" +"\n"
+ "[1] L" + "\n"
+ "[2] Coca Cola" + "\n"
+ "[3] Sprite" + "\n"
+ "[4] Mountain Dew" + "\n"
+ "[5] Pepsi" + "\n"
+ "[6] Cofee" +"\n"
+ "[7] Hot Choco" + "\n"
+ "[8] Nestie Iced Tea" +"\n"
+ "[9] Exit" +"\n"
+ "Enter Your Choice:"));
}
switch(choice)
{
case 1:
price = 20;
bibilhin= " Lemonade";
break;
case 2:
price = 20;
bibilhin= "Coca Cola ";
break;
case 3:
price =820;
bibilhin = "Sprite";
break;
case 4:
price =205;
bibilhin= "Mountain dew";
break;
case 5:
price =20;
bibilhin= "Pepsi";
break;
case 6:
price =25;
bibilhin= "Cofee ";
break;
case 7:
price =25;
bibilhin= "Hot Choco";
break;
case 8:
price = 20;
bibilhin= "Nestie Ice tea";
break;
case 9:
JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"You are about to exit!","Exit",JOptionPane.WARNING_MESSAGE);
do{
con=Integer.parseInt(JOptionPane.showInputDialog("Are you sure you want to exit?\n[1] Yes\n[0] No"));
if(con==1)
System.exit(0);
else if(con==1)
{
JOptionPane.showMessageDialog(null,"THANK YOU!\nGood Bye!","Exit",JOptionPane.ERROR_MESSAGE);
break;
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
con=1;
}
}while(con==1);
continue;
default:
JOptionPane.showMessageDialog(null,"Invalid Choice!","ERROR",JOptionPane.ERROR_MESSAGE);
}
do{//do1
qty = Integer.parseInt(JOptionPane.showInputDialog("Quantity:"));
if (qty>0)
break;
else
{
JOptionPane.showMessageDialog(null,"Invalid Input!","Error",JOptionPane.ERROR_MESSAGE);
continue;
}
}while(q==1);//end do1
total = price * qty;
ptotal = ptotal+total;
order = order +bibilhin+" "+qty+" "+price+"="+total+"\n";
do {//do2
con = Integer.parseInt(JOptionPane.showInputDialog("Continue?[1] yes [0] no"));
if(con==1)
{
break;
}
else if(con==0)
{
do{
pay = Integer.parseInt(JOptionPane.showInputDialog(order+"Total " +ptotal+"\nEnter Payment:"));
if(pay>=ptotal)
{
change = pay-ptotal;
JOptionPane.showMessageDialog(null," \t Mang Inasal"+
"\n\t 14 T molina st purok 6-B "+
"\n\t Alabang Muntinlupa City "+
"\nOperator: Micko Mendoza"+
"\n\t----------------------------------------------------------------"+
"\n\n\t "+order+"\nTotal "+ptotal+
"\nCash "+pay+
"\nChange "+change+
"\n----------------------------------------------------------------"+
"\n\n \t Thanks For buying!!!!!"+
"\n\t This Serve as an official reciept DTSN:41D983"+
"\n \t For Delivery Dial (519-6936)"+
"\n \t Feedbacks"+
"\n \t micko.mendoza#yahoo.com"
);
y=0;
z=0;
x=1;
gtotal = gtotal+ptotal;
trans++;
order="";
transaction = transaction+"Transaction "+ trans+ " "+ptotal+"\n";//No of transactions
ptotal = 0;
do{
con=Integer.parseInt(JOptionPane.showInputDialog("Next Customer?\n[1] Yes\n[0] No"));
if(con==1)
break;
else if(con==0)
{
JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
continue;
}
}while(con==1);
break;
}
else
{
JOptionPane.showMessageDialog(null,"Kulang pera mo");
continue;
}
}while(z==1);//do3
}
else
{
JOptionPane.showMessageDialog(null,"Intiger lang pwede","Continue",JOptionPane.ERROR_MESSAGE);
y=1;
continue;
}
} while(y==1);//do2
break;
switch(food)
{
case 11:
price = 20;
bibilhin= " Lemonade";
break;
case 12:
price = 20;
bibilhin= "Coca Cola ";
break;
case 13:
price =820;
bibilhin = "Sprite";
break;
case 14:
price =205;
bibilhin= "Mountain dew";
break;
case 15:
price =20;
bibilhin= "Pepsi";
break;
case 16:
price =25;
bibilhin= "Cofee ";
break;
case 17:
price =25;
bibilhin= "Hot Choco";
break;
case 18:
price = 20;
bibilhin= "Nestie Ice tea";
break;
case 19:
JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"You are about to exit!","Exit",JOptionPane.WARNING_MESSAGE);
do{
con=Integer.parseInt(JOptionPane.showInputDialog("Are you sure you want to exit?\n[1] Yes\n[0] No"));
if(con==1)
System.exit(0);
else if(con==1)
{
JOptionPane.showMessageDialog(null,"THANK YOU!\nGood Bye!","Exit",JOptionPane.ERROR_MESSAGE);
break;
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
con=1;
}
}while(con==1);
continue;
default:
JOptionPane.showMessageDialog(null,"Invalid Choice!","ERROR",JOptionPane.ERROR_MESSAGE);
}
do{//do1
qty = Integer.parseInt(JOptionPane.showInputDialog("Quantity:"));
if (qty>0)
break;
else
{
JOptionPane.showMessageDialog(null,"Invalid Input!","Error",JOptionPane.ERROR_MESSAGE);
continue;
}
}while(q==1);//end do1
total = price * qty;
ptotal = ptotal+total;
order = order +bibilhin+" "+qty+" "+price+"="+total+"\n";
do {//do2
con = Integer.parseInt(JOptionPane.showInputDialog("Continue?[1] yes [0] no"));
if(con==1)
{
break;
}
else if(con==0)
{
do{
pay = Integer.parseInt(JOptionPane.showInputDialog(order+"Total " +ptotal+"\nEnter Payment:"));
if(pay>=ptotal)
{
change = pay-ptotal;
JOptionPane.showMessageDialog(null," \t Mang Inasal"+
"\n\t 14 T molina st purok 6-B "+
"\n\t Alabang Muntinlupa City "+
"\nOperator: Micko Mendoza"+
"\n\t----------------------------------------------------------------"+
"\n\n\t "+order+"\nTotal "+ptotal+
"\nCash "+pay+
"\nChange "+change+
"\n----------------------------------------------------------------"+
"\n\n \t Thanks For buying!!!!!"+
"\n\t This Serve as an official reciept DTSN:41D983"+
"\n \t For Delivery Dial (519-6936)"+
"\n \t Feedbacks"+
"\n \t micko.mendoza#yahoo.com"
);
y=0;
z=0;
x=1;
gtotal = gtotal+ptotal;
trans++;
order="";
transaction = transaction+"Transaction "+ trans+ " "+ptotal+"\n";//No of transactions
ptotal = 0;
do{
con=Integer.parseInt(JOptionPane.showInputDialog("Next Customer?\n[1] Yes\n[0] No"));
if(con==1)
break;
else if(con==0)
{
JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
continue;
}
}while(con==1);
break;
}
else
{
JOptionPane.showMessageDialog(null,"Kulang pera mo");
continue;
}
}while(z==1);//do3
}
else
{
JOptionPane.showMessageDialog(null,"Intiger lang pwede","Continue",JOptionPane.ERROR_MESSAGE);
y=1;
continue;
}
} while(y==1);//do2
continue;
}
}
}
You have an unconditional break right before the switch in question.
As an aside, I think this is the perfect time to learn about functions and how to use them to make code more modular.
comment the break statement
import javax.swing.;
import java.awt.;
public class Test{
public static void main(String[] args)
{
int choice=0,food=0,c=0,con,x=1,y=1,z=1,q=1,trans=0,price=0 ,qty,gtotal=0,ptotal=0,pay,change,total=0,ord;
String order="",bibilhin="",transaction="",A;
ImageIcon welcome = new ImageIcon("welcome.jpg");
ImageIcon chip = new ImageIcon("chip.jpg");
ImageIcon rc = new ImageIcon("rc.jpg");
ImageIcon stick = new ImageIcon("stick.jpg");
ImageIcon pancit = new ImageIcon("pancit.jpg");
ImageIcon jampong = new ImageIcon("jampong.jpg");
ImageIcon chups = new ImageIcon("chups.jpg");
ImageIcon egg = new ImageIcon("egg.jpg");
A=JOptionPane.showInputDialog("Enter your name:"); ImageIcon hansel = new ImageIcon("hansel.jpg");
JOptionPane.showMessageDialog(null,"Sir/Ma`am \n "+A+"\n Welcome\n to Mang Inasal\n Please Choose The\n product you want to buy","Welcome" ,JOptionPane.PLAIN_MESSAGE,welcome);
while(x==1)
{
c=Integer.parseInt(JOptionPane.showInputDialog(" Categories" + "\n" +"[1] Drinks" + "\n" + "[2] Foods"));
if(c==1)
{choice=Integer.parseInt(JOptionPane.showInputDialog("DRINKS" +"\n"
+ "[1] Lemonade" + "\n"
+ "[2] Coca Cola" + "\n"
+ "[3] Sprite" + "\n"
+ "[4] Mountain Dew" + "\n"
+ "[5] Pepsi" + "\n"
+ "[6] Cofee" +"\n"
+ "[7] Hot Choco" + "\n"
+ "[8] Nestie Iced Tea" +"\n"
+ "[9] Exit" +"\n"
+ "Enter Your Choice:"));
if(c==2)
food=Integer.parseInt(JOptionPane.showInputDialog("Food" +"\n"
+ "[1] L" + "\n"
+ "[2] Coca Cola" + "\n"
+ "[3] Sprite" + "\n"
+ "[4] Mountain Dew" + "\n"
+ "[5] Pepsi" + "\n"
+ "[6] Cofee" +"\n"
+ "[7] Hot Choco" + "\n"
+ "[8] Nestie Iced Tea" +"\n"
+ "[9] Exit" +"\n"
+ "Enter Your Choice:"));
}
switch(choice)
{
case 1:
price = 20;
bibilhin= " Lemonade";
break;
case 2:
price = 20;
bibilhin= "Coca Cola ";
break;
case 3:
price =820;
bibilhin = "Sprite";
break;
case 4:
price =205;
bibilhin= "Mountain dew";
break;
case 5:
price =20;
bibilhin= "Pepsi";
break;
case 6:
price =25;
bibilhin= "Cofee ";
break;
case 7:
price =25;
bibilhin= "Hot Choco";
break;
case 8:
price = 20;
bibilhin= "Nestie Ice tea";
break;
case 9:
JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"You are about to exit!","Exit",JOptionPane.WARNING_MESSAGE);
do{
con=Integer.parseInt(JOptionPane.showInputDialog("Are you sure you want to exit?\n[1] Yes\n[0] No"));
if(con==1)
System.exit(0);
else if(con==1)
{
JOptionPane.showMessageDialog(null,"THANK YOU!\nGood Bye!","Exit",JOptionPane.ERROR_MESSAGE);
break;
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
con=1;
}
}while(con==1);
continue;
default:
JOptionPane.showMessageDialog(null,"Invalid Choice!","ERROR",JOptionPane.ERROR_MESSAGE);
}
do{//do1
qty = Integer.parseInt(JOptionPane.showInputDialog("Quantity:"));
if (qty>0)
break;
else
{
JOptionPane.showMessageDialog(null,"Invalid Input!","Error",JOptionPane.ERROR_MESSAGE);
continue;
}
}while(q==1);//end do1
total = price * qty;
ptotal = ptotal+total;
order = order +bibilhin+" "+qty+" "+price+"="+total+"\n";
do {//do2
con = Integer.parseInt(JOptionPane.showInputDialog("Continue?[1] yes [0] no"));
if(con==1)
{
break;
}
else if(con==0)
{
do{
pay = Integer.parseInt(JOptionPane.showInputDialog(order+"Total " +ptotal+"\nEnter Payment:"));
if(pay>=ptotal)
{
change = pay-ptotal;
JOptionPane.showMessageDialog(null," \t Mang Inasal"+
"\n\t 14 T molina st purok 6-B "+
"\n\t Alabang Muntinlupa City "+
"\nOperator: Micko Mendoza"+
"\n\t----------------------------------------------------------------"+
"\n\n\t "+order+"\nTotal "+ptotal+
"\nCash "+pay+
"\nChange "+change+
"\n----------------------------------------------------------------"+
"\n\n \t Thanks For buying!!!!!"+
"\n\t This Serve as an official reciept DTSN:41D983"+
"\n \t For Delivery Dial (519-6936)"+
"\n \t Feedbacks"+
"\n \t micko.mendoza#yahoo.com"
);
y=0;
z=0;
x=1;
gtotal = gtotal+ptotal;
trans++;
order="";
transaction = transaction+"Transaction "+ trans+ " "+ptotal+"\n";//No of transactions
ptotal = 0;
do{
con=Integer.parseInt(JOptionPane.showInputDialog("Next Customer?\n[1] Yes\n[0] No"));
if(con==1)
break;
else if(con==0)
{
JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
continue;
}
}while(con==1);
break;
}
else
{
JOptionPane.showMessageDialog(null,"Kulang pera mo");
continue;
}
}while(z==1);//do3
}
else
{
JOptionPane.showMessageDialog(null,"Intiger lang pwede","Continue",JOptionPane.ERROR_MESSAGE);
y=1;
continue;
}
} while(y==1);//do2
// break;
switch(food)
{
case 11:
price = 20;
bibilhin= " Lemonade";
break;
case 12:
price = 20;
bibilhin= "Coca Cola ";
break;
case 13:
price =820;
bibilhin = "Sprite";
break;
case 14:
price =205;
bibilhin= "Mountain dew";
break;
case 15:
price =20;
bibilhin= "Pepsi";
break;
case 16:
price =25;
bibilhin= "Cofee ";
break;
case 17:
price =25;
bibilhin= "Hot Choco";
break;
case 18:
price = 20;
bibilhin= "Nestie Ice tea";
break;
case 19:
JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"You are about to exit!","Exit",JOptionPane.WARNING_MESSAGE);
do{
con=Integer.parseInt(JOptionPane.showInputDialog("Are you sure you want to exit?\n[1] Yes\n[0] No"));
if(con==1)
System.exit(0);
else if(con==1)
{
JOptionPane.showMessageDialog(null,"THANK YOU!\nGood Bye!","Exit",JOptionPane.ERROR_MESSAGE);
break;
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
con=1;
}
}while(con==1);
continue;
default:
JOptionPane.showMessageDialog(null,"Invalid Choice!","ERROR",JOptionPane.ERROR_MESSAGE);
}
do{//do1
qty = Integer.parseInt(JOptionPane.showInputDialog("Quantity:"));
if (qty>0)
break;
else
{
JOptionPane.showMessageDialog(null,"Invalid Input!","Error",JOptionPane.ERROR_MESSAGE);
continue;
}
}while(q==1);//end do1
total = price * qty;
ptotal = ptotal+total;
order = order +bibilhin+" "+qty+" "+price+"="+total+"\n";
do {//do2
con = Integer.parseInt(JOptionPane.showInputDialog("Continue?[1] yes [0] no"));
if(con==1)
{
break;
}
else if(con==0)
{
do{
pay = Integer.parseInt(JOptionPane.showInputDialog(order+"Total " +ptotal+"\nEnter Payment:"));
if(pay>=ptotal)
{
change = pay-ptotal;
JOptionPane.showMessageDialog(null," \t Mang Inasal"+
"\n\t 14 T molina st purok 6-B "+
"\n\t Alabang Muntinlupa City "+
"\nOperator: Micko Mendoza"+
"\n\t----------------------------------------------------------------"+
"\n\n\t "+order+"\nTotal "+ptotal+
"\nCash "+pay+
"\nChange "+change+
"\n----------------------------------------------------------------"+
"\n\n \t Thanks For buying!!!!!"+
"\n\t This Serve as an official reciept DTSN:41D983"+
"\n \t For Delivery Dial (519-6936)"+
"\n \t Feedbacks"+
"\n \t micko.mendoza#yahoo.com"
);
y=0;
z=0;
x=1;
gtotal = gtotal+ptotal;
trans++;
order="";
transaction = transaction+"Transaction "+ trans+ " "+ptotal+"\n";//No of transactions
ptotal = 0;
do{
con=Integer.parseInt(JOptionPane.showInputDialog("Next Customer?\n[1] Yes\n[0] No"));
if(con==1)
break;
else if(con==0)
{
JOptionPane.showMessageDialog(null,transaction+"Total sales: " + gtotal,"Transactions",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Choice!","Error",JOptionPane.ERROR_MESSAGE);
continue;
}
}while(con==1);
break;
}
else
{
JOptionPane.showMessageDialog(null,"Kulang pera mo");
continue;
}
}while(z==1);//do3
}
else
{
JOptionPane.showMessageDialog(null,"Intiger lang pwede","Continue",JOptionPane.ERROR_MESSAGE);
y=1;
continue;
}
} while(y==1);//do2
continue;
}
}
}

Categories