The following code is ice cream party calculator. All I am working through right now is the first ageCheck. Right now where it states boolean genderCheck = choice == 1;. The code below runs some calculations and works fine. But then when I added boolean genderCheck = choice == 2; it states the variable has already been declared and wont work. How can I fix my code so that after passing the first ageCheck the second j option pane will take both numbers 1 and 2. Also called choice ==1 and choice ==2;?
import javax.swing.JOptionPane;
public class l{
public static void main (String[] args) {
int amount= Integer.parseInt(JOptionPane.showInputDialog( "How many Guest are coming?:"));
int e;
double cc;
double pc;
double sax= 17.95;
double tnt;
double o;
double d= 1.06;
double vla=2.03;
boolean ageCheck = (amount>=1) && (amount<=19);
boolean ageCheck2 = (amount>=20);
if (ageCheck) {
int choice= Integer.parseInt(JOptionPane.showInputDialog( " PLEASE ENTER EITHER 1 or 2; 1 is donut ice cream which is 99 cents and 2 is vanilia ice cream that is $1.99?:"));
boolean genderCheck = choice == 1;
e = 2;
pc = ((amount/2.0) );
o =Math.ceil(pc);
tnt = o *sax;
cc = (amount*d);
boolean genderCheck = choice == 2;
e = 2;
pc = ((amount/2.0) );
o =Math.ceil(pc);
tnt = o *sax;
cc = (amount*vla);
if (genderCheck) {
JOptionPane.showMessageDialog(
null, "The Cost Peer Room is : " + e + " ICE COST: "+tnt+"MORE COST" +cc+" TOTAL COST" + (e+tnt+cc));}
else {
JOptionPane.showMessageDialog(null,"Error: Gender must be F or M") ;
}}
else if (ageCheck2) {
String choice = JOptionPane.showInputDialog( "Enter Flavor: Vanilla =$1 Donut = $2 ");
boolean genderCheck2 = choice.equalsIgnoreCase("M") || choice.equalsIgnoreCase("F");
if (genderCheck2) {
JOptionPane.showMessageDialog(null,"OUTPUT: YOUR 2 Years old and either a boy or girl");
} else {
JOptionPane.showMessageDialog(null,"Error: You did not enter male or female as gender") ;
}
} else {
JOptionPane.showMessageDialog(null,"Error: There must be atleast 1 guest") ;
}
}}
Aucun commentaire:
Enregistrer un commentaire