Menu

[solved] – Question 8971

·It captures the “NumberFormatException” that is thrown if a string cannot be converted to a number. When the exception is captured, the user must be informed that he is an idiot.
·Define a new exception called “NotMemberException”. The exception must be thrown if the registration number entered by the user does not exist in the list of StudInfo. Your program should catch the exception as follows. It should first try to see if the number before and after the one entered exists. If so, it informs the user that they probably made a typo and provides them the name of the found student. If neither is found it must simply inform the user that such registration number does not exist.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package exhandassgn;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
*
* @author christoforos
*/
public class Main {

/**
* @param args the command line arguments
*/
static ArrayList<StudInfo> ls;

public static void main(String[] args) {
populate();
System.out.println(“Enter a registration number:”);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
String inp = in.readLine();
int rVal = Integer.parseInt(inp);
StudInfo foundStudent = getStudent(rVal);
System.out.println(foundStudent.getName());
}
catch(IOException ioe) {System.out.println(ioe.getMessage());}
}

static void pop

Expert Answer


OR


Leave a Reply

Your email address will not be published. Required fields are marked *