# I ned a while loop statment that makes the calculations loop and ask again

im not too sure how you add a loop statement to this. I want it to be a while loop that makes it do that the calculations repeat after finishing. I've tried but it just keeps on giving me errors. ive tried doing While statements but just will not work im not sure how you set it up as my teacher did not explain very well

``````import com.godtsoft.diyjava.DIYWindow;

public class Calculator extends DIYWindow {

public Calculator() {

// getting number one
double number1 = promptForDouble("Enter a number");

//getting number2
int number2 = promptForInt("Enter an integer");

//getting what to do with operation
print("What do you want to do with these numbers?\nAdd\tSubtract\tMultiply\tDivide");
String operation = input();
//declaring variable here so the same one can be used
switch(operation) {
print(number1 + " + " + number2 + " = " + answer);
break;
case "subtract":
print(number1 + " - " + number2 + " = " + answer);
break;
case "multiply":
print(number1 + " * " + number2 + " = " + answer);
break;
case "divide":

try {
}
catch(ArithmeticException e) {
print("A number cannot be divided by 0.");
}
print(number1 + " / " + number2 + " = " + answer);
break;
}

double double1 = promptForDouble("Enter a number");
double double2 = promptForDouble("Enter another number");
double double3 = promptForDouble("Enter one last number");
print("What do you want to do with these numbers?\nAdd\tSubtrack\tMultiply\tDivide");
String operation2 = input();
switch(operation2) {
answer2 = double1 + double2 + double3;
print(double1 + " + " + double2 + " + " + double3 + " = " + answer2);
break;
case "subtract":
answer2 = double1 - double2 - double3;
print(double1 + " - " + double2 + " - " + double3 + " = " + answer2);
break;
case "multiply":
answer2 = double1 * double2 * double3;
print(double1 + " * " + double2 + " * " + double3 + " = " + answer2);
break;
case "divide":

try {
answer2 = double1 / double2 / double3;
}
catch(ArithmeticException e) {
print("A number cannot be divided by 0.");
}
print(double1 + " / " + double2 + " / " + double3 + " = " + answer2);
break;
}

want it to loop after the code on top

}

private double promptForDouble(String prompt) {
double number1 = 0;
print(prompt);
String number = input();

try {
number1 = Double.parseDouble(number);
}
catch(NumberFormatException e){
print("That is not a number. Please enter a number.");
number1 = promptForDouble(prompt);
}
return number1;
}

private int promptForInt(String prompt) {
int number2 = 0;
print(prompt);
String number = input();

try {

number2 = Integer.parseInt(number); }
catch(NumberFormatException e) {
print("That is not an integer. Enter an integer.");
number2 = promptForInt(prompt); }
return number2;
}

public static void main(String[] args) {
new Calculator();

}

}
``````

``````while (true)