I have to create a Java program that lets the user interact with it, so they can learn about exceptions. How do I let the user interact with a list of options and direct them to a catch statement?  Here is my program so far:  import java.util.Scanner; import java.io.*; import java.util.InputMismatchException; public class Exceptions{               public static void main(String[] args)throws IOException{                // declare variables       char option = 'y';              //Arithhmetic & Array TEST       int array[] = {10,20,30,40};       int num1 = 50;       int num2 = 10;                 // Setting up scanner to get user data       Scanner exc = new Scanner(System.in);              // Main method (menu, try-catch block)          // all within a loop          try {          }       // I want to learn how an ArrayIndexOutOfBoundsException...          catch(ArrayIndexOutOfBoundsException exception) {             System.out.println("This exception is thrown when the array index that was entered is out of bounds.");          }       // I want to learn how an ArithhmeticException...(mathematics)          catch(ArithmeticException exception) {             System.out.println("This exception is thrown when an exceptional condition has occurred in an arithmetic operation 0");          }            // I want to learn how an FileNotFoundException...          catch(FileNotFoundException exception) {             System.out.println("This exception is thrown when a file is not accessible or does not open. (ex. the file does not exist or is located in a folder the program doesn't have access to).");          }       // I want to learn how an InputMismatchException...          catch(InputMismatchException exception) {             System.out.println("This exception is thrown when the input entered is not an integer, but written as the word and not the number (ex. two instead of the integer 2).");          }            // I want to learn how an StringIndexOutOfBoundsException...          catch(StringIndexOutOfBoundsException exception) {                System.out.println("This exception is thrown when a the index entered is outside of the bounds the string was set to");          }            // I want to learn how an NoSuchMethodException...          catch(NoSuchMethodException exception) {                System.out.println("This exception is thrown when a method does not exist or isn't recgonized from another class");          }                       // end of try-catch block              // Display the menu and have the user try as many times as the want           i++;             System.out.println("Would you like to try another Unchecked Exception? (y/n)");             option = exc.next().charAt(0);            // menu method       while(option == 'y') {          System.out.println("Enter 1 if you want to learn about ArrayIndexOutOfBoundsException");          System.out.println("Enter 2 if you want to learn about ArithmeticException");          System.out.println("Enter 3 if you want to learn about FileNotFoundException");          System.out.println("Enter 4 if you want to learn about InputMismatchException");          System.out.println("Enter 5 if you want to learn about StringIndexOutOfBoundsException");          System.out.println("Enter 6 if you want to learn about NoSuchMethodException");       }           // end of main method    }  }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

I have to create a Java program that lets the user interact with it, so they can learn about exceptions. How do I let the user interact with a list of options and direct them to a catch statement? 

Here is my program so far: 

import java.util.Scanner;
import java.io.*;
import java.util.InputMismatchException;

public class Exceptions{           
   public static void main(String[] args)throws IOException{  
      
      // declare variables
      char option = 'y';
      
      //Arithhmetic & Array TEST
      int array[] = {10,20,30,40};
      int num1 = 50;
      int num2 = 10;   
      
      // Setting up scanner to get user data
      Scanner exc = new Scanner(System.in);
      
      // Main method (menu, try-catch block)
         // all within a loop
         try {

         }
      // I want to learn how an ArrayIndexOutOfBoundsException...
         catch(ArrayIndexOutOfBoundsException exception) {
            System.out.println("This exception is thrown when the array index that was entered is out of bounds.");
         }
      // I want to learn how an ArithhmeticException...(mathematics)
         catch(ArithmeticException exception) {
            System.out.println("This exception is thrown when an exceptional condition has occurred in an arithmetic operation 0");
         }     
      // I want to learn how an FileNotFoundException...
         catch(FileNotFoundException exception) {
            System.out.println("This exception is thrown when a file is not accessible or does not open. (ex. the file does not exist or is located in a folder the program doesn't have access to).");
         }
      // I want to learn how an InputMismatchException...
         catch(InputMismatchException exception) {
            System.out.println("This exception is thrown when the input entered is not an integer, but written as the word and not the number (ex. two instead of the integer 2).");
         }     
      // I want to learn how an StringIndexOutOfBoundsException...
         catch(StringIndexOutOfBoundsException exception) {
               System.out.println("This exception is thrown when a the index entered is outside of the bounds the string was set to");
         }     
      // I want to learn how an NoSuchMethodException...
         catch(NoSuchMethodException exception) {
               System.out.println("This exception is thrown when a method does not exist or isn't recgonized from another class");
         }
            
         // end of try-catch block
      
      // Display the menu and have the user try as many times as the want
          i++;
            System.out.println("Would you like to try another Unchecked Exception? (y/n)");
            option = exc.next().charAt(0);
    
      // menu method
      while(option == 'y') {
         System.out.println("Enter 1 if you want to learn about ArrayIndexOutOfBoundsException");
         System.out.println("Enter 2 if you want to learn about ArithmeticException");
         System.out.println("Enter 3 if you want to learn about FileNotFoundException");
         System.out.println("Enter 4 if you want to learn about InputMismatchException");
         System.out.println("Enter 5 if you want to learn about StringIndexOutOfBoundsException");
         System.out.println("Enter 6 if you want to learn about NoSuchMethodException");
      }
   
      // end of main method
   }
 }

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY