我不知道我在做什么,但你可以在推出退出按钮时使用 当我输入结束时,或者在输入中输入任何东西时总是这样 回到起点。我只是一个乞讨者请帮助!
import javax.swing.JOptionPane;
public class SariStoreTrial
{
public static void main( String[] args ){
String welcome = "Welcome Aranduque's Sari Sari Store Program";
JOptionPane.showMessageDialog(null, welcome);
//BEVERAGES
String beverage;
String repeat;
do{
beverage = JOptionPane.showInputDialog(null, "\"BEVERAGES\"\n1. Coca Cola-10\n2. RC Cola-10\n3. Pop Cola-10\n4. Sparkle-10\n5. Cheers-10\n6. Sprite-10\n7. Mountain Dew-10\n8. Royal Thru Orange-10\n9. Seven Up-10\n10. Pepsi Cola-10\nOr Type \"No\"\nEnter your number of Choice Below!");
switch (beverage) {
case "1" ://Coca Cola ---------------------------------------------------
int quant;
int mon;
int buy;
int change;
int price = 10;
String quantity = JOptionPane.showInputDialog(null, "A Coca Cola Cost P10\nHow Much Would You Like To Buy?");
String money = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant = Integer.parseInt (quantity);
mon = Integer.parseInt (money);
buy = quant*10;
change = mon - buy;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity+ " Pieces Of Coca Cola For A Total Of P" +buy+"\nAnd Your Change Is P"+change+"\n========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nCoca Cola - "+quantity+" Pieces\n----------------------------------------\nTotal - P"+buy+"\n Amount - P"+mon+"\n Change - P"+change+"\n****************************************");
break;
case "2" ://RC Cola ---------------------------------------------------
int quant2;
int mon2;
int buy2;
int change2;
String quantity2 = JOptionPane.showInputDialog(null, "A RC Cola Cost P10\nHow Much Would You Like To Buy?");
String money2 = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant2 = Integer.parseInt (quantity2);
mon2 = Integer.parseInt (money2);
buy2 = quant2*10;
change2 = mon2 - buy2;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity2+ " Pieces Of Coca Cola For A Total Of P" +buy2+"\nAnd Your Change Is P"+change2+"\n ========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nRC Cola - "+quantity2+" Pieces\n----------------------------------------\nTotal - P"+buy2+"\n Amount - P"+mon2+"\n Change - P"+change2+"\n****************************************");
break;
case "3" ://Pop Cola ---------------------------------------------------
int quant3;
int mon3;
int buy3;
int change3;
String quantity3 = JOptionPane.showInputDialog(null, "A Pop Cola Cost P10\nHow Much Would You Like To Buy?");
String money3 = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant3 = Integer.parseInt (quantity3);
mon3 = Integer.parseInt (money3);
buy3 = quant3*10;
change3 = mon3 - buy3;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity3+ " Pieces Of Pop Cola For A Total Of P" +buy3+"\nAnd Your Change Is P"+change3+"\n ========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nPop Cola - "+quantity3+" Pieces\n----------------------------------------\nTotal - P"+buy3+"\n Amount - P"+mon3+"\n Change - P"+change3+"\n****************************************");
break;
case "4" ://Sparkle ---------------------------------------------------
int quant4;
int mon4;
int buy4;
int change4;
String quantity4 = JOptionPane.showInputDialog(null, "A Sparkle Cost P10\nHow Much Would You Like To Buy?");
String money4 = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant4 = Integer.parseInt (quantity4);
mon4 = Integer.parseInt (money4);
buy4 = quant4*10;
change4 = mon4 - buy4;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity4+ " Pieces Of Sparkle For A Total Of P" +buy4+"\nAnd Your Change Is P"+change4+"\n ========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nSparkle - "+quantity4+" Pieces\n----------------------------------------\nTotal - P"+buy4+"\n Amount - P"+mon4+"\n Change - P"+change4+"\n****************************************");
break;
case "5" ://Cheers ---------------------------------------------------
int quant5;
int mon5;
int buy5;
int change5;
String quantity5 = JOptionPane.showInputDialog(null, "A Cheers Cost P10\nHow Much Would You Like To Buy?");
String money5 = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant5 = Integer.parseInt (quantity5);
mon5 = Integer.parseInt (money5);
buy5 = quant5*10;
change5 = mon5 - buy5;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity5+ " Pieces Of Cheers For A Total Of P" +buy5+"\nAnd Your Change Is P"+change5+"\n ========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nCheers - "+quantity5+" Pieces\n----------------------------------------\nTotal - P"+buy5+"\n Amount - P"+mon5+"\n Change - P"+change5+"\n****************************************");
break;
case "6" ://Sprite ---------------------------------------------------
int quant6;
int mon6;
int buy6;
int change6;
String quantity6 = JOptionPane.showInputDialog(null, "A Sprite Cost P10\nHow Much Would You Like To Buy?");
String money6 = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant6 = Integer.parseInt (quantity6);
mon6 = Integer.parseInt (money6);
buy6 = quant6*10;
change6 = mon6 - buy6;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity6+ " Pieces Of Sprite For A Total Of P" +buy6+"\nAnd Your Change Is P"+change6+"\n ========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nSprite - "+quantity6+" Pieces\n----------------------------------------\nTotal - P"+buy6+"\n Amount - P"+mon6+"\n Change - P"+change6+"\n****************************************");
break;
case "7" ://Mountain Dew ---------------------------------------------------
int quant7;
int mon7;
int buy7;
int change7;
String quantity7 = JOptionPane.showInputDialog(null, "A Mountain Dew Cost P10\nHow Much Would You Like To Buy?");
String money7 = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant7 = Integer.parseInt (quantity7);
mon7 = Integer.parseInt (money7);
buy7 = quant7*10;
change7 = mon7 - buy7;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity7+ " Pieces Of Mountain Dew For A Total Of P" +buy7+"\nAnd Your Change Is P"+change7+"\n ========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nMountain Dew - "+quantity7+" Pieces\n----------------------------------------\nTotal - P"+buy7+"\n Amount - P"+mon7+"\n Change - P"+change7+"\n****************************************");
break;
case "8" ://Royal Thru Orange ---------------------------------------------------
int quant8;
int mon8;
int buy8;
int change8;
String quantity8 = JOptionPane.showInputDialog(null, "A Royal Thru Orange Cost P10\nHow Much Would You Like To Buy?");
String money8 = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant8 = Integer.parseInt (quantity8);
mon8 = Integer.parseInt (money8);
buy8 = quant8*10;
change8 = mon8 - buy8;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity8+ " Pieces Of Royal Thru Orange For A Total Of P" +buy8+"\nAnd Your Change Is P"+change8+"\n ========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nRoyal Thru Orange - "+quantity8+" Pieces\n----------------------------------------\nTotal - P"+buy8+"\n Amount - P"+mon8+"\n Change - P"+change8+"\n****************************************");
break;
case "9" ://Seven Up ---------------------------------------------------
int quant9;
int mon9;
int buy9;
int change9;
String quantity9 = JOptionPane.showInputDialog(null, "A Seven Up Cost P10\nHow Much Would You Like To Buy?");
String money9 = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant9 = Integer.parseInt (quantity9);
mon9 = Integer.parseInt (money9);
buy9 = quant9*10;
change9 = mon9 - buy9;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity9+ " Pieces Of Seven Up For A Total Of P" +buy9+"\nAnd Your Change Is P"+change9+"\n ========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nSeven Up - "+quantity9+" Pieces\n----------------------------------------\nTotal - P"+buy9+"\n Amount - P"+mon9+"\n Change - P"+change9+"\n****************************************");
break;
case "10" ://Pepsi Cola ---------------------------------------------------
int quant10;
int mon10;
int buy10;
int change10;
String quantity10 = JOptionPane.showInputDialog(null, "A Pepsi Cola Cost P10\nHow Much Would You Like To Buy?");
String money10 = JOptionPane.showInputDialog(null,"Enter Your Money!");
quant10 = Integer.parseInt (quantity10);
mon10 = Integer.parseInt (money10);
buy10 = quant10*10;
change10 = mon10 - buy10;
JOptionPane.showMessageDialog(null, "========================================\nYou Bought " +quantity10+ " Pieces Of Pepsi Cola For A Total Of P" +buy10+"\nAnd Your Change Is P"+change10+"\n ========================================");
JOptionPane.showMessageDialog(null, "****************************************\n\"ITEMS PURCHASED RECEIPT\"\nPepsi Cola - "+quantity10+" Pieces\n----------------------------------------\nTotal - P"+buy10+"\n Amount - P"+mon10+"\n Change - P"+change10+"\n****************************************");
break;
case "No" ://Nothing ---------------------------------------------------
JOptionPane.showMessageDialog(null, "You did'nt choose anything!");
break;
case "no" ://Nothing ---------------------------------------------------
JOptionPane.showMessageDialog(null, "You did'nt choose anything!");
break;
default://Default ---------------------------------------------------
JOptionPane.showMessageDialog(null, "It is not on Store!");
break;
}
repeat = JOptionPane.showInputDialog(null, "\"Enter\"\nX - Exit\nZ - Return");
}while (repeat!="Z");
System.exit(0);