I’m working on a computer science question and need an explanation and answer to help me learn.
GMU Fall 2022 – CS 211 – Exercise 2
Objective
The purpose of this assignment is to practice menus, exceptions, and unit testing. You will implement and modify a few classes that solve a programming task, and then you will write a small tester to test your code. No tester will be provided for this assignment.
Overview
Analyze the Shape Manager class and the interface it uses, Area-calculator.
Analyze the Shape class hierarchy, used to represent a limited set of shapes.
Analyze the menu named Measuring Unit, used to represent the shape sides’ unit of measurement (FEET, or METER).
Implement the exception classes Shape Exception, Measuring Unit Exception and Area Calculator Exception, which shall be used to signal improper values and impossible actions relating to classes.
Write a class named E2Tester that performs unit testing for the classes.
Prepare the assignment for submission and submit it through Blackboard
Background
During use of the classes, sometimes we may accidentally try to feed bad values into a method. In these cases, the program should raise an exception. The unit tester should be able to verify that the code is properly signaling the illegal operations via exceptions.
However, unchecked exceptions are a controversial topic. The client using your Application Program Interface (API) is expected to be NASA and the Pentagon, so no exception left unchecked. In Java, your API consists of the public classes and their public members (fields, methods).
We will relax such requirement to checking for the following Java Unchecked Exceptions:
Null Pointer Exception (NPE)
Array Index Out of Bounds Exception (AIOBE)
Arithmetic Exception (AE)
Illegal Argument Exception (IAE)
Illegal State Exception (ISE)You will mask those unchecked exceptions within the realm of the three exceptions listed above for this exercise
You must change the behavior of the following classes, so they support the MeasuringUnit enum and handle the implemented masked exceptions:
NOTE:
Change the behavior of code means to edit the code so it complies to a desired intent.
Handling an exception means that the code enforces an exception’s scenarios correctly, either by catching the exception, propagating it, or both. You must edit the code, so it handles an exception.
Implementing a method means write code that satisfies an intended behavior. For example, an interface has methods that need to be implemented. Each method description in an interface specifies a contract, the intended behavior of the method when used by others. A class that implements an interface, needs to satisfy the contract of each method in the interface.
ShapeManager
You must implement the AreaCalculator methods. The methods are defined but not fully implemented. Make sure the shapes’ measuring units are the same as you implement the calculations.
You must handle that all methods in this class catch possible unchecked exceptions and propagate the correct masked exceptions.
Shape
You must handle that all methods in this class catch possible unchecked exceptions and propagate the correct masked exceptions.
Square
You must handle that all methods in this class catch possible unchecked exceptions and propagate the correct masked exceptions.
Rectangle
You must implement the AreaCalculator methods. The methods are defined but not fully implemented. Make sure the shape’s measuring units is based on its unit’s field. You must handle that all methods in this class catch possible unchecked exceptions and propagate the correct masked exceptions.
E2Tester
You must write your own tester. An empty template is provided for your convenience. Be warned though that the tests in the template are empty and an empty test will naively “pass” the tester because no assert statement has failed.
This is the starting point for solving the exercise, please follow the commands at the top
of the file to edit-n-run your code.
This does not mean that the tester is correct! You must fill in the template with actual tests before you start testing your solution. If your solution passes all the tests of your own tester, a question that arises is how good your tester is. Did you pass the tests because the solution is correct or because the tester is unable to detect any errors? To verify that your tester is good, make a backup of your code and then start introducing bugs to your solution. For every bug you create, use your tester to check if it can detect the failure. The more defects it detects the better the tester is.
Be sure to make tests for each class’s method, inspect them one-by-one and line-by-line, it will help you notice where exceptions may arise. Your tests should be able to handle exceptions and normal program execution.
Now,
Gotta Catch ’Em All
Grading
Grading has two parts with 50-50 weight:
To grade your solution, we will use our own tester that, unlike previous assignments, isnot provided to you for obvious reasons.
To grade your tester, we will use a defective version of the solution and we will count howmany bugs your tester can detect. The more errors your tester finds the higher your score will be.
If your program throws any exception other than the ones masked by you, that is, they do NOT extend CheckedRuntimeException, points will be deducted.
If you are handling exceptions unrelated to the code at hand, points will be deducted. Each unrelated exceptions weights double than a correct one, be cautious.
Submission
Submission instructions are as follows:
Let xxx be your lab section number and let yyyyyyyy be your GMU userid. Create thedirectory xxx_yyyyyyyy_E2.
Place your files in the directory you’ve just created.
Create the file ID.txt in the format shown below, containing your name, userid, G#, lecturesection and lab section, and add it to the directory. Full Name: GeorgeMasonuserID: gmason
G#: 01234567 Lecture section: 003 Lab section: 213
Compress the folder and its contents into a .zip file and upload the file to Blackboard.
Upload a backup of the .zip file to OneDrive
Download the files you uploaded to Blackboard and OneDrive, unzip them, recompile andtest them, in order to verify that they’re both correct.