Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class named Colorpoint with the following fields: x x coordinate on a plane y y coordinate on a plane colorR red color component

Design a class named Colorpoint with the following fields: x x coordinate on a plane y y coordinate on a plane colorR red color component colorG green color component colorB blue color component All member variables are of type int. Write a non-argument constructor that sets all variables to 0. Write a constructor that takes all the data about the point position and color as parameters (4 parameters) and initializes fields. Write appropriate accessor and mutator methods for these fields: o setXY(int x, iny); setRGB(int r, int g, int b) o getR(); getG; getB(); getX(); getY(); Override toString() and equals() methods for the class Create a custom exception class called InvalidRgbException that will be used when the color field of your new class is incorrectly set. As you know, each color component value must not be more than 225 and less than 0.

Add data validation code to constructor that takes parameters and to setRGB() method. In each of the methods throw InvalidRgbException if the value for red, green, or blue is out of correct range. In the exception message specify the color field that was incorrectly set and the value it was set to. Name your project ColorPointDemo.java Test all methods you wrote in main. Place main() in a file separate from all the classes named ColorPointDemo.java. Make sure to use try/catch block to catch custom exceptions that are thrown by your methods. Write tests that demonstrate that the exceptions are being thrown and caught. ColorPoint Class and Binary File I/O Continue working with the same project. In the file next to main() create two new methods: public static ColorPoint[] readColorPointArray(String fileName) and public static void writeColorPointArray(String fileName, ColorPoint[] points) Both methods must throw I/OExceptions. The I/OExceptions may originate in the methods but must not be handled. All exceptions must be propagated to the calling code. Please handle ClassNotFoundException in the readColorPointArray() method. readColorPointArray()method reads the contents of a binary file and places it into an array of objects of type ColorPoint. Assume you do not know the amount of data in the file. When reading the file store the objects in ArrayList first. After the end of file has been reached, convert the ArrayList into a regular array and return it from method. writeColorPointArray()method writes the contents of the given array into the given binary file. In main() create an array of ColorPoint objects of size 10. Populate the array with objects that have random values for colors use random number generator to set RGB fields, and (x, y) set to (0, 0)(9, 9). Pass that array to the method writeColorPointArray() to be stored in a file colorPoints.dat. Then use readColorPointArray()method to read the stored data from file and display it into the screen. The text file we are reading is supposed to be filled with integers, one integer per line. If one of the lines contains a corrupted piece of data (not an integer), the MultiCatch program stops, reports an error and exits. Change the flow of control in the sample code in such a way that a corrupted line (or multiple lines) of text file does not prevent the program to continue printing out the rest of the numbers from the file. Call your project FixedMultiCatch.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

Do you currently have a team agreement?

Answered: 1 week ago

Question

How will the members be held accountable?

Answered: 1 week ago