Actually the for loop works it's just that what I am having to do is pushed through with JOptionPane output. It will only print out the last part of the loop when it needs to print all the runs. This is what I have:
// import java.util.Scanner; import javax.swing.JOptionPane; public class ApplianceTest4 { public static void main(String args[]) { Scanner input = new Scanner(System.in); String repeat; int counter; String choice; double purchase1; double purchase2; String message=""; int chosen; String amount; int x; String amount2; int y; int i; Appliance app1 = new Appliance("washer", "Kenmore", 102956, 299.99); Appliance app2 = new Appliance("stove", "GE", 8956, 575.75); repeat = JOptionPane.showInputDialog("Please enter how many purchese are going to be made:\n"); counter = Integer.parseInt(repeat); for(i = 1; i <= counter; i++) { choice = JOptionPane.showInputDialog("Type 1 if purchasing washer or 2 for stove: "); chosen = Integer.parseInt(choice); switch(chosen) { case 1: { amount = JOptionPane.showInputDialog("Enter the amount of washers:\n"); x = Integer.parseInt(amount); purchase1 = app1.getPrice() * x; message = String.format("You purchased %s washers for $%.2f.\n", x, purchase1); break; } case 2: {amount2 = JOptionPane.showInputDialog("Enter the amount of stoves:"); y = Integer.parseInt(amount2); purchase2 = app2.getPrice() * y; message = String.format("You purchased %s stoves for $%.2f.\n", y, purchase2); break;} default: {message = String.format("Incorrect choice choose 1 or 2"); break;} } } JOptionPane.showMessageDialog(null, message + i); } }
Hopefully somebody can show me where I went wrong.