This homework has 2 problems which deal with text files and exceptions (Ch 12).
Eclipse Reminder
You will create a Java Project in Eclipse with the name: hw5_FLastname You will have two packages: prob1, prob2
Problem 1
For this problem you modify the Rectangle class to throw a custom exception if an attempt is made to create an illegal rectangle. The program will read a file of potential rectangles and write the illegal ones to a file.
Create a package named prob1 Download the classes GeometricObject and Rectangle from BlazeView and copy them to the prob1 package. Read (no action required) – An illegal rectangle is one whose area is less than 1.0.
Create a class named IllegalRectangleException – This class should be a subtype (subclass) of RuntimeException. Its constructor should accept a message, the width, height, and area of an illegal rectangle. It should also make available these values.
Modify the Rectangle class to throw an IllegalRectangleException when an attempt is made to create an illegal rectangle.
Create a text file named rectangles.txt in your prob1 folder with the sample values shown below. Each line represents a rectangle: width and height. Note: there are 6 possible rectangles in this sample file, but in general there could be any number.
3.5 4.5
0.5 0.25
0.4 0.9
8
7
1 0.2
Create a class named RectangleTester which should read from rectangles.txt. It should read all the rectangles in the file, one at a time. Any rectangles that are illegal should be written to an output file named illegalRectangles.txt. If the input is as above, then illegalRectangles.txt should produce this output:
For this problem you will read a file of numbers adding them as you go, but skipping some of the number as indicated by a code in the file.
Create a package named prob2
Create a text file named numbers.txt in your prob2 folder with the sample values shown below. Note: the third line is the letter “s” followed by the number “2”. Similarly, the ninth line is the letter “s” followed by the number “1”. This will be explained next.
4
5
s2
99
2
17
1
8
s1
7
10
10
5
Create a class named NumberAdder that has a main that reads numbers.txt and adds all numbers except the ones skipped as indicated by a line in the file that starts with the letter “s” and is followed by the number of lines to skip. Finally, the sum should be printed to the console. For example, the input below:
would produce the output: Sum=60
Here is another test case which should produce the output: Sum=90
s5
2
43
3
6
2 9
12
4
56
s2
10
4
8
s2
1
5
s2
4
2
10
Submission
Make sure you zip the ENTIRE folder hw5_FLastname!! Submit your zip file to Blazeview by the due date. The name of your file should be: hw5_FLastname.zip.
Grading
I will RANDOMLY select one problem for grading. For example, if problem 1 is selected, I will only go to the package/folder prob1 for grading. So make sure all your Java codes are in the correct packages/folders.
Additional Requirements:
No late submission will be accepted. Please exactly follow the naming rules described above. You will be deducted 10 points for incorrect naming.
Write comments at the beginning of your Java source file(s) to indicate your name, student ID, “CS 1302-A Homework 5”, and the due date.
Make sure that your programs are well-documented, readable, and user friendly. Make sure you document your programs by adding comments to your statements/blocks so that I can understand your code. You will get 0 to 10 points based on the helpfulness of your comments. You will be deducted 10 points for no comments.
It is your responsibility to make sure your programs can compile and run correctly. Please be aware that programs that do not compile may receive ZERO credit.
When grades are returned to you via BlazeView, you have 7 days to meet with the instructor to discuss on grade changes. After 7 days, the grades are written in stone and can't be changed after that point.