Question: Question 1 Open the Exercise project ( the Exercise folder ) . Complete the following by editing CourseCode.java ( a ) Write a method addCourseCode
Question
Open the Exercise project the Exercise folder
Complete the following by editing CourseCode.java
a Write a method addCourseCodeString courseCode to add a new course code to the courseCodeSet attribute.
b In main method, create a CourseCode object name courseCode. Add the following course code to the object.
COMPSEF
COMPSEF
COMPSEF
COMP
COMPSEF
c Write a method printCourseCodeLevel to display the level of each course code stored in the courseCodeSet. The level is represented by an integer that located at the fifth character of the course code. For example, COMPSEF is a level course.
Hint:
String method substring can be used to extract the course level in String type from the course code.
o StringIndexOutOfBoundsException will be thrown if an index is either negative or greater than the size of the string.
Method Integer.parseInt can be used to convert the extracted course level into an integer.
o NumberFormatException will be thrown if a string is converted to one of the numeric types, but it does not have the appropriate format.
Implement an exception handler in the method to handle the StringIndexOutOfBoundsException and NumberFormatException with a trycatch statement. If StringIndexOutOfBoundsException is caught, displays a message Improper course code length: and the course code. If NumberFormatException is caught, displays a message Invalid course code format: and the course code.
d In main method, test the method printCourseCodeLevel
Capture Output
COMPSEF: Level
COMPSEF: Level
COMPSEF: Level
Improper course code length: COMP
Invalid course code format: COMPSEF
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
