Tuesday 23 January 2018

Code with problem in java

import javax.swing.JOptionPane;
import java.util.Scanner;

public class CodeWithProblem
{
    public static void main (String[] args)
    {
        String name, gender, passions, enjoy;
        int yesNo, permission, endProgram;
        String prefix = "";
        while (true)
        {
            name = JOptionPane.showInputDialog("Please enter your name: ","Name");
            if (name.equals("null"))
            {
                System.exit(0);
            }
            yesNo = JOptionPane.showConfirmDialog(null, "So your name is  "+name+". Is this correct?", "", JOptionPane.YES_NO_OPTION);
            if (yesNo == -1)
            {
                System.exit(0);
            }
            if (yesNo == 0)
            {
                break;
            }
        }
        while (true)
        {
            gender = JOptionPane.showInputDialog("Are you a boy or a girl?: ");
            if (gender.equals("null"))
            {
                System.exit(0);
            }
            if ("boy".equalsIgnoreCase(gender)||"girl".equalsIgnoreCase(gender))
            {
                break;
            }
        }
        if ("boy".equalsIgnoreCase(gender))
        {
            prefix = "Mr. ";
        }
        if ("girl".equalsIgnoreCase(gender))
        {
            prefix = "Ms. ";
        }
        JOptionPane.showMessageDialog(null, "It's nice to meet you "+prefix+name+".", "Hello", JOptionPane.PLAIN_MESSAGE);
        permission = JOptionPane.showConfirmDialog(null, "Lets ask some easy questions to start out with. Is this okay with you?: ",
        "", JOptionPane.YES_NO_OPTION);
        if (permission == 1)
        {
            endProgram = JOptionPane.showConfirmDialog(null, "Do you want to end this program? Click CANCEL to end and OKAY to continue.",
            "End Program?", JOptionPane.OK_CANCEL_OPTION);
            if (endProgram == 0)
            {
                JOptionPane.showMessageDialog(null, "Good, lets continue...", "Continue", JOptionPane.PLAIN_MESSAGE);
                permission = 0;
            }
            if (endProgram == 1)
            {
                JOptionPane.showMessageDialog(null, "Goodbye....", "END", JOptionPane.PLAIN_MESSAGE);
               
            }
        }
        if (permission == 0)
        {
            passions = JOptionPane.showInputDialog("What are some of your passions?: ");
            if (passions.equals("null"))
            {
                System.exit(0);
            }
            enjoy = JOptionPane.showInputDialog("Why do you enjoy "+passions+"?: ");
            if (enjoy.equals("null"))
            {
                System.exit(0);
            }
            JOptionPane.showMessageDialog(null, "That's interesting", "hmmm", JOptionPane.PLAIN_MESSAGE);
            JOptionPane.showMessageDialog(null, "This program has no point and is going to end now.", "BACON", JOptionPane.PLAIN_MESSAGE);
        }
    }
}

0 comments: