Guest User

Untitled

a guest
Nov 20th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1.  
  2. import javax.swing.JOptionPane;
  3.  
  4. public class MainFile
  5. {
  6.  
  7.     public static void main(String[] args)
  8.     {
  9.         String option = JOptionPane.showInputDialog("Declare Method Number");
  10.         int choice = 0;
  11.         try
  12.         {
  13.             choice = Integer.parseInt(option);
  14.         }
  15.         catch(NumberFormatException e)
  16.         {
  17.             System.out.println("enter a number between one and six");
  18.             System.exit(0);
  19.         }
  20.         if(choice > 6 || choice < 1)
  21.         {
  22.             System.out.println("enter a number between one and six");
  23.         }
  24.         switch(choice)
  25.         {
  26.             case 1:
  27.                 drawTypeOne();
  28.                 break;
  29.             case 2:
  30.                 drawTypeTwo();
  31.                 break;
  32.             case 3:
  33.                 drawTypeThree();
  34.                 break;
  35.             case 4:
  36.                 sum10Reciprocals();
  37.                 break;
  38.             case 5:
  39.                 dialogPane();
  40.                 break;
  41.             case 6:
  42.                 homework();
  43.                 break;
  44.            
  45.         }
  46.     }
  47.    
  48.    
  49.     /**
  50.      * Draws a robot face
  51.      */
  52.     public static void drawTypeOne()
  53.     {
  54.         System.out.println("  /////  ");
  55.         System.out.println(" | o o | ");
  56.         System.out.println("(|  ^  |)");
  57.         System.out.println(" | [_] | ");
  58.         System.out.println("  -----  ");
  59.     }
  60.  
  61.     /**
  62.      * Draws the second pattern
  63.      */
  64.     public static void drawTypeTwo()
  65.     {
  66.         String p1 = "+---+---+---+";
  67.         String p2 = "|   |   |   |";
  68.         for(int x = 0; x < 3; x++)
  69.         {
  70.             System.out.println(p1);
  71.             System.out.println(p2);
  72.         }
  73.         System.out.println(p1);
  74.     }
  75.    
  76.     /**
  77.      * Draws the third pattern
  78.      */
  79.     public static void drawTypeThree()
  80.     {
  81.         String p1 = "+---";
  82.         String p2 = "|   ";
  83.         String p3 = "    ";
  84.        
  85.         System.out.println(p3+p3+p3+p1+"+");
  86.         System.out.println(p3+p3+p3+p2+"|");
  87.         System.out.println(p3+p3+p1+p1+"+");
  88.         System.out.println(p3+p3+p2+p2+"|");
  89.         System.out.println(p3+p1+p1+p1+"+");
  90.         System.out.println(p3+p2+p2+p2+"|");
  91.         System.out.println(p1+p1+p1+p1+"+");
  92.         System.out.println(p2+p2+p2+p2+"|");
  93.         System.out.println(p1+p1+p1+p1+"+");
  94.     }
  95.    
  96.     public static void sum10Reciprocals()
  97.     {
  98.         float sum = 0;
  99.         for(float x = 1; x <= 10; x++)
  100.         {
  101.             sum+= (1/x);
  102.         }
  103.        
  104.         System.out.println(sum);
  105.     }
  106.    
  107.     public static void dialogPane()
  108.     {
  109.         String name = JOptionPane.showInputDialog("What is your name");
  110.         System.out.println(name);
  111.         System.exit(0);
  112.     }
  113.    
  114.     public static void homework()
  115.     {
  116.         String name = JOptionPane.showInputDialog("What is your name?");
  117.         JOptionPane.showInputDialog("What should I do?");
  118.         JOptionPane.showInternalMessageDialog(null , "I'm sorry, "+ name+", I can't do that");
  119.         System.exit(0);
  120.     }
  121.    
  122. }
Add Comment
Please, Sign In to add comment