Java代写 | COMP1406 – Assignment #6

本次Java代写是练习使用递归以及文件操作
COMP1406 – Assignment #6
(1) The PartImage class
Download the provided A6-Base-Code.zip 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
booleans.
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:
0,0,0,0,0,0,0,0,0,0
0,1,1,1,1,1,1,0,0,0
0,1,1,1,1,1,1,0,0,0
0,0,0,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,1,1,0
0,1,1,1,1,1,1,0,0,0
0,0,0,0,1,1,1,0,0,0
0,0,0,0,0,0,0,0,0,0
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.
———-
-******—
-******—
-********-
—******-
-********-
-********-
-******—
—-***—
———-
COMP 1406 – W20 – A6 Due Friday, April 24th at 11:59 PM Due Friday, March 20th at 11:59 PM
• 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.
• Complete the partSize() method so that it returns an int representing the number of black
pixels in the image. This can be done using a double FOR loop.
• Complete the method called expandFrom(int r, int c) that recursively examines the image by
traversing its pixels, examining (i.e., “visiting”) black pixels in all directions that are connected to a
starting point black pixel (specified by the parameters). The idea is that this method will determine
all black pixels that are connected to the starting pixel. Additionally, the method should set the
black pixels to white (hints: when a white pixel is encountered during the recursion, this is an indication
that you don’t need to keep recursively checking in that direction). This method MUST be done
recursively without loops, otherwise you will receive 0 marks for this part.
• Complete the method called perimeterOf(int r, int c) which should return an integer representing
the perimeter of the part which starts at the given (r,c) point. The method MUST be done
recursively without loops, otherwise you will receive 0 marks for this part. For example, in
the image (A) shown above, the perimeter is 36 (which is the red border length, not the number of
black cells on the border) and in image (B) it is 106. As for the other two images, it depends
where you started expanding from, since the piece is broken into multiple parts. (hints: You will
need to mark pixels as being visited (perhaps use another 2D array). Make sure not to re-visit these
pixels. Also, make sure to handle borders correctly. A black pixel on the top/left border corner, for
example, will add 2 to the perimeter count for the top and the left.)


程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


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

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


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论