Java代写 | COMP1406 – Assignment #6

COMP1406 – Assignment #6
(1) The PartImage class
Download the provided file and extract the included IntelliJ project. This project
contains a PartImage class, which represents one of these images using a 2-dimensional array of
You must complete the following methods in the PartImage class. Note that all the recursive methods may
be implemented in a ‘destructive’ sense. That is, you can change the state of the object within your
recursive implementation and do not need to recover to the original starting state.
• Complete the static readFromFile(String fileName) method that will open the specified file,
which will contain the data for a single part’s image. This method must read the part image data
from the file and return a new PartImage object with the correct attributes to represent that part
image. The data in the file will be organized like a 2D array, with each line representing a row
of the part’s image data. Each row will contain some number of comma-separated 0s and 1s,
indicating a white or a black space respectively. For example, the data contained in a file
representing part (a) from above might look like:
Note that you cannot assume that you know how wide each row will be or how many rows are
present. You will have to compute this in order to initialize the size of any 2D boolean arrays
your class uses. Three possible exceptions could arise within this method:
1. FileNotFoundException – if the specified file is not found, your method’s code should
handle the exception gracefully and return a null object.
2. IOException – if there is another type of input error, your method’s code should
handle the exception gracefully and return a null object.
3. InvalidPartImageException – if any line in the file does not contain the same number
of values as all other lines (e.g., 9 columns in one line and 10 in another), or one of
the values is not 0/1, your method must throw a new InvalidPartImageException with
the current filename. This exception will be handled by the provided test code.
• Complete the print() method that will print out the image in the console window which mayprint
something like what is shown below for the image in picture (a) above.
• Complete the findStart() method that returns the location (row/column) of any black pixel in the
image. It uses the Point2D as the return value. If no black pixel is found, the method should
return null.


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:itcsdx