Question: The Java mechanism to handle issues of data integrity at runtime is through Exceptions. We want to add to our code base the rejection of

The Java mechanism to handle issues of data integrity at runtime is through Exceptions. We want to add to our code base the rejection of any guess or answer that violates our constraints. We also want to enforce programmatically that people use our methods to ask for valid data, and do not do things like ask for the 6th color of our guess. Java already provides several exception classes that we could use, such as IllegalArgumentException and IndexOutOfBoundsException. The IllegalArugmentException is very broad however, and only via its message can we distinguish what the cause of the exception might have been. So we want to create two new exceptions:

1.MastermindIllegalColorException

2.MastermindIllegalLengthException That should capture the case that a method was provided with a guess or answer that contained a color not part of our original six colors (MastermindIllegalColorException). The MastermindIllegalLengthException should be thrown if a guess or answer is not 4 colors long. These should be checked exceptions, and the Mastermind class should handle the exceptions to enforce that the user's input is always legal. If it is not, display a message indicating why the input was illegal and ask them to try again. Do not count the invalid guess as one of the 10 guesses of the game. Note: In the Model-View-Controller architecture, only the View should be interacting with the user. That means no prints or input in any class other than Mastermind. For any other issues your code may encounter at runtime, use one of the standard Java Class Library Exceptions to report it. As part of your testing, you should add new test cases to your JUnit test suite that check that invalid input results in exceptions being thrown. Use the assertThrows() assertion to test. The first project was graded based on a cooperative user. This project will be graded attempting to break your methods.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!