import javax.swing.*;
import java.text.*;
public class Postage3{
public static void main(String args[]){
double weight, cost, count;
int choice, choice2;
DecimalFormat df = new DecimalFormat ("0.00");
choice2 = 1;
while(choice2 == 1){
weight = Double.parseDouble(JOptionPane.showInputDialog("Enter weight of postage according to ounces"));
if(weight <= 1){
cost = weight * 0.30;
}
else{
count = (weight - 1) / 0.5;
cost = (1 * 0.30) + (count * 0.11);
}
choice = Integer.parseInt(JOptionPane.showInputDialog("Special Delivery?" +"\n"
+"Type [1] for Yes [0] for No"));
if(choice == 1)
JOptionPane.showMessageDialog(null, "Weight of Letter: " +weight +"\n"
+"Postage cost: " +df.format(cost) +"\n"
+"Special Delivery is 5.00" +"\n"
+"Total Cost: " +df.format(cost+5));
else if(choice == 0)
JOptionPane.showMessageDialog(null, "Weight of Letter: " +weight +"\n"
+"Postage cost: " +df.format(cost) +"\n"
+"Total Cost: " +df.format(cost));
else
JOptionPane.showMessageDialog(null, "Please input only 1 or 0");
//I want it to restart here after displaying error
choice2 = Integer.parseInt(JOptionPane.showInputDialog("Do you want another transaction?" +
"\nPress [1] for YES [0] for NO"));
if(choice2 == 0)
JOptionPane.showMessageDialog(null, "Thank You. Have a nice day.");
else if(choice2 != 1 && choice2 != 0)
JOptionPane.showMessageDialog(null, "ERROR Please Input [1] or [0] only");
}
System.exit(0);
}
}
I want my program to restart to choice2 input question after displaying the error dialog box.