Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class MainFile
- {
- public static void main(String[] args)
- {
- String option = JOptionPane.showInputDialog("Declare Method Number");
- int choice = 0;
- try
- {
- choice = Integer.parseInt(option);
- }
- catch(NumberFormatException e)
- {
- System.out.println("enter a number between one and six");
- System.exit(0);
- }
- if(choice > 6 || choice < 1)
- {
- System.out.println("enter a number between one and six");
- }
- switch(choice)
- {
- case 1:
- drawTypeOne();
- break;
- case 2:
- drawTypeTwo();
- break;
- case 3:
- drawTypeThree();
- break;
- case 4:
- sum10Reciprocals();
- break;
- case 5:
- dialogPane();
- break;
- case 6:
- homework();
- break;
- }
- }
- /**
- * Draws a robot face
- */
- public static void drawTypeOne()
- {
- System.out.println(" ///// ");
- System.out.println(" | o o | ");
- System.out.println("(| ^ |)");
- System.out.println(" | [_] | ");
- System.out.println(" ----- ");
- }
- /**
- * Draws the second pattern
- */
- public static void drawTypeTwo()
- {
- String p1 = "+---+---+---+";
- String p2 = "| | | |";
- for(int x = 0; x < 3; x++)
- {
- System.out.println(p1);
- System.out.println(p2);
- }
- System.out.println(p1);
- }
- /**
- * Draws the third pattern
- */
- public static void drawTypeThree()
- {
- String p1 = "+---";
- String p2 = "| ";
- String p3 = " ";
- System.out.println(p3+p3+p3+p1+"+");
- System.out.println(p3+p3+p3+p2+"|");
- System.out.println(p3+p3+p1+p1+"+");
- System.out.println(p3+p3+p2+p2+"|");
- System.out.println(p3+p1+p1+p1+"+");
- System.out.println(p3+p2+p2+p2+"|");
- System.out.println(p1+p1+p1+p1+"+");
- System.out.println(p2+p2+p2+p2+"|");
- System.out.println(p1+p1+p1+p1+"+");
- }
- public static void sum10Reciprocals()
- {
- float sum = 0;
- for(float x = 1; x <= 10; x++)
- {
- sum+= (1/x);
- }
- System.out.println(sum);
- }
- public static void dialogPane()
- {
- String name = JOptionPane.showInputDialog("What is your name");
- System.out.println(name);
- System.exit(0);
- }
- public static void homework()
- {
- String name = JOptionPane.showInputDialog("What is your name?");
- JOptionPane.showInputDialog("What should I do?");
- JOptionPane.showInternalMessageDialog(null , "I'm sorry, "+ name+", I can't do that");
- System.exit(0);
- }
- }
Add Comment
Please, Sign In to add comment