Hello, I am attempting to make a program that simulates a magic 8 ball. You ask questions and it will respond accordingly, for the most part I have most of the program written and it all compiles, however, I am trying to get the program to loop and ask if the user wants to go again but it does seem to want to. I am having a bit of trouble with loops can anyone help show me how to approach this problem? I apologize if my program is all over the place I am still new.
import javax.swing.JOptionPane; import java.util.Random; import java.util.Scanner; public class Magic8Ball { public static void main(String[] args) { Scanner input = new Scanner(System.in); String userInput = JOptionPane.showInputDialog("What is your question?"); String answer = Magic8Ball(); JOptionPane.showMessageDialog(null, answer); JOptionPane.showInputDialog("Would you like to try again? Y or N"); String again = input.nextLine(); if(again.equals("Y") || again.equals("y")) { do{ JOptionPane.showInputDialog("What is you question?"); JOptionPane.showMessageDialog(null, answer); JOptionPane.showInputDialog("Would you like to try again? Y or N"); String again2 = input.nextLine(); }while(again.equals("Y") || again.equals("y")); } else{ JOptionPane.showMessageDialog(null, "Have a nice day."); } } public static String Magic8Ball() { Random rand = new Random(); String[] responses = { "it is certain.", "It is decidedly so.", "Without a doubt.", "Yes - definitely.", "You may rely on it.", "As I see it, yes.", "Most likely.", "Outlook good.", "Yes.", "Signs point to yes.", "Reply hazy, try again.", "Ask again later.", "Better not tell you now.", "Cannot predict now.", "Concentrate and ask again.", "Don't count on it.", "My reply is no.", "My sources say no.", "Outlook not so good.", "Definitely not.", "Very doubtful.", }; return responses[new Random().nextInt(responses.length)]; } }