Hi, I need help with this assignment I need to help with FloodFill.java In the A1_Python_code.zip file,
Fantastic news! We've Found the answer you've been seeking!
Question:
Hi, I need help with this assignment I need to help with FloodFill.java
Transcribed Image Text:
In the A1_Python_code.zip file, you will find a working version of the flood fill algorithm written in Python. The module index2.py contains the definition of a Python class named Index2 that represents a two-dimensional index. The module flood_fill.py contains a runnable Python program made up of several functions that flood fills a two-dimensional list. Your assignment is to translate the Python file flood_fill.py into the Java class FloodFill.java. The only file that you should modify is FloodFill.java . The file Index2.java defines a type that you will use to represent a two-dimensional index, and the file FloodFillUtil.java defines a class that provides methods to draw a two-dimensional array and read a two-dimensional array from a file. The file in the package princeton.introcs defines a class that can be used for drawing simple images. One of the methods has already been translated for you: • The Python function print_array has been translated to the Java method printArray The main method of FloodFill.java has already been implemented for you, but will not run because the main method calls the missing methods of the class. You do not need to document your code for this assignment. Later assignments will have you writing lots of documentation. Hints The assignment is straightforward if you keep the following in mind: • The main method should run successfully if you translate the code correctly. If it does not run successfully, then you have done something incorrectly. DO NOT modify the main method so that your code words; modify your code so that the main method works. • The Python program uses an underscore to separate words in multiword function names (for example, test_array_not_empty) • 。 You should use the Java convention of lower camelcase variable and method names (for example, testArrayNotEmpty ) The Python program is made up of several functions. 。 Java has no functions. You should translate the Python functions into public static methods in this assignment. • The order and types of the parameters matter when translating the Python functions to Java methods. 。 the type of the two-dimensional index is Index2 。 the type of the two-dimensional array is int[][] 。 the type of the elements in the array is int • In Python, a two-dimensional list is a list where the elements of the list are other lists. For example, a 5 × 5 grid of values can be represented by a list containing 5 sublists where each sublist contains 5 values. To obtain the number of rows in a two-dimensional list t we can write rows = len(t) If there is at least one row, then the number of columns can be obtained by writing cols = len(t[0]) (the number of elements in the first row). 。 In Java, we can use a two-dimensional array instead of a list of lists. A two-dimensional array int ( ) ( ) is an array where the elements are arrays of int ■the number of rows in a two-dimensional array arr is equal to arr.length ■this is equal to the number of arrays in arr ■ the number of columns is equal to the length of the first array in the array if there is one ■ this is equal to arr[0].length if arr[0] exists • In Python, a function can validate the arguments to the function and then raise an exception if an argument has an invalid value. 。 In Java, a method can throw an exception when an invalid argument is detected. In this assignment, you should throw an IllegalArgumentException when an invalid argument is detected. • The Python program uses a class named Index2 to represent a two-dimensional index. An Index2 object has attributes named respectively. • 。 The Java class Index2.java defines a class that is very similar to the Python class of the same name. row and col to represent the row index and column index, 。 In Java, you can create an Index2 object by using the new operator and a constructor. For example, to create an Index2 object representing row and column indexes of 1 and 3 we can write Index2 i = new Index2 (1, 3) . • To get the row and column indexes from an Index2 object we can write int r = i.row and int c = i.col (similar to how you access the indexes in the Python program) Pay close attention when translating the flood_fill function. The Python function says that your Java method should include the line FloodFillUtil.draw(arr); where indicated. This is needed to allow the Java program to draw the array. Running the program If you successfully translate the Python code to Java, then running the FloodFill.java program should draw a picture. The default starting array has Os (the constant BORDER ) on the first and last rows and columns, and 1s (the constant INTERIOR) everywhere else. The INTERIOR values are replaced with REPLACEMENT Array values equal to BORDER INTERIOR and REPLACEMENT are drawn in black, white, and yellow, respectively. The following image shows the starting array (left) and the flood filled array (right): If you uncomment the line //arr = FloodFillUtil.readArray("face.txt"); in the main method, then the program flood fills the interior of a face. The following image shows the starting array (left) and the flood filled array (right): 回 If you uncomment the line //arr = FloodFillUtil.readArray("random.txt"); in the main method, then the program flood fills the interior of an array containing a semi-random sequence of Os and 1s. The following image shows the starting array (left) and the flood filled array (right): AA Extra notes ⚫ the mapping of values to colors is defined in FloodFillUtil.java • the main method always start the flood fill at row=3, col=3 (the fourth row and column) 。 changing the starting indexes may affect what gets filled ⚫ the face and random arrays are defined in the files face.txt and random.txt 。 you can create your own files if you want; save them in the a1 folder 。 the number of rows and columns can be different, but the program always draws into a square canvas In the A1_Python_code.zip file, you will find a working version of the flood fill algorithm written in Python. The module index2.py contains the definition of a Python class named Index2 that represents a two-dimensional index. The module flood_fill.py contains a runnable Python program made up of several functions that flood fills a two-dimensional list. Your assignment is to translate the Python file flood_fill.py into the Java class FloodFill.java. The only file that you should modify is FloodFill.java . The file Index2.java defines a type that you will use to represent a two-dimensional index, and the file FloodFillUtil.java defines a class that provides methods to draw a two-dimensional array and read a two-dimensional array from a file. The file in the package princeton.introcs defines a class that can be used for drawing simple images. One of the methods has already been translated for you: • The Python function print_array has been translated to the Java method printArray The main method of FloodFill.java has already been implemented for you, but will not run because the main method calls the missing methods of the class. You do not need to document your code for this assignment. Later assignments will have you writing lots of documentation. Hints The assignment is straightforward if you keep the following in mind: • The main method should run successfully if you translate the code correctly. If it does not run successfully, then you have done something incorrectly. DO NOT modify the main method so that your code words; modify your code so that the main method works. • The Python program uses an underscore to separate words in multiword function names (for example, test_array_not_empty) • 。 You should use the Java convention of lower camelcase variable and method names (for example, testArrayNotEmpty ) The Python program is made up of several functions. 。 Java has no functions. You should translate the Python functions into public static methods in this assignment. • The order and types of the parameters matter when translating the Python functions to Java methods. 。 the type of the two-dimensional index is Index2 。 the type of the two-dimensional array is int[][] 。 the type of the elements in the array is int • In Python, a two-dimensional list is a list where the elements of the list are other lists. For example, a 5 × 5 grid of values can be represented by a list containing 5 sublists where each sublist contains 5 values. To obtain the number of rows in a two-dimensional list t we can write rows = len(t) If there is at least one row, then the number of columns can be obtained by writing cols = len(t[0]) (the number of elements in the first row). 。 In Java, we can use a two-dimensional array instead of a list of lists. A two-dimensional array int ( ) ( ) is an array where the elements are arrays of int ■the number of rows in a two-dimensional array arr is equal to arr.length ■this is equal to the number of arrays in arr ■ the number of columns is equal to the length of the first array in the array if there is one ■ this is equal to arr[0].length if arr[0] exists • In Python, a function can validate the arguments to the function and then raise an exception if an argument has an invalid value. 。 In Java, a method can throw an exception when an invalid argument is detected. In this assignment, you should throw an IllegalArgumentException when an invalid argument is detected. • The Python program uses a class named Index2 to represent a two-dimensional index. An Index2 object has attributes named respectively. • 。 The Java class Index2.java defines a class that is very similar to the Python class of the same name. row and col to represent the row index and column index, 。 In Java, you can create an Index2 object by using the new operator and a constructor. For example, to create an Index2 object representing row and column indexes of 1 and 3 we can write Index2 i = new Index2 (1, 3) . • To get the row and column indexes from an Index2 object we can write int r = i.row and int c = i.col (similar to how you access the indexes in the Python program) Pay close attention when translating the flood_fill function. The Python function says that your Java method should include the line FloodFillUtil.draw(arr); where indicated. This is needed to allow the Java program to draw the array. Running the program If you successfully translate the Python code to Java, then running the FloodFill.java program should draw a picture. The default starting array has Os (the constant BORDER ) on the first and last rows and columns, and 1s (the constant INTERIOR) everywhere else. The INTERIOR values are replaced with REPLACEMENT Array values equal to BORDER INTERIOR and REPLACEMENT are drawn in black, white, and yellow, respectively. The following image shows the starting array (left) and the flood filled array (right): If you uncomment the line //arr = FloodFillUtil.readArray("face.txt"); in the main method, then the program flood fills the interior of a face. The following image shows the starting array (left) and the flood filled array (right): 回 If you uncomment the line //arr = FloodFillUtil.readArray("random.txt"); in the main method, then the program flood fills the interior of an array containing a semi-random sequence of Os and 1s. The following image shows the starting array (left) and the flood filled array (right): AA Extra notes ⚫ the mapping of values to colors is defined in FloodFillUtil.java • the main method always start the flood fill at row=3, col=3 (the fourth row and column) 。 changing the starting indexes may affect what gets filled ⚫ the face and random arrays are defined in the files face.txt and random.txt 。 you can create your own files if you want; save them in the a1 folder 。 the number of rows and columns can be different, but the program always draws into a square canvas
Expert Answer:
Answer rating: 100% (QA)
Sure Based on the hints provided it seems like you need assistance with implementing the Flood Fill ... View the full answer
Related Book For
Exploring Marketing Research
ISBN: 978-1305263529
11th Edition
Authors: Barry J. Babin, William G. Zikmund
Posted Date:
Students also viewed these programming questions
-
for the equality test for M and N. The question concerns how to represent multisets of strings within ML. For each of the given data representations (a), (b) and (c) describe how you would implement...
-
123 Compare the purely graphical properties of these two notations, and the ways in which the graphical properties of each display correspond to the information structure being defined. Describe...
-
Write a memo to an employee whose work and behavior have been unsatisfactory. (You are the department manager.) Try to motivate the employee to improve his performance. Be brief, direct, honestand as...
-
Explain the difference between c-charts and p-charts.
-
Use the shell method to write and evaluate the definite integral that represents the volume of the solid generated by revolving the plane region about the x-axis. y = 4x 2 , x = 0, y = 4
-
The enzyme lipase catalyzes the hydrolysis of esters of fatty acids. The hydrolysis of p-nitrophenyloctanoate was followed by measuring the appearance of p-nitrophenol in the reaction mixture: The...
-
The following probabilistic activity time estimates are for the CPM/PERT network in Problem Determine the following: a. Expected activity times b. Earliest start and finish times c. Latest starts and...
-
The following information is presented for the year-end reporting for Alcoy, LLC: Sales Price per Unit $24, Total Fixed Costs 150,000, Variable Cost per Unit 8, Total Units Sold 14,000. How much is...
-
b. Prepare all consolidating entries needed to prepare consolidated statements for 20X5. (If no entry is required for a transaction/event, select "No journal entry required" in the first account...
-
Jamison Computer Sales Store order 150 computer desks. The supply company shipped 150 printer stands. Does the shipment amount to an acceptance of the offer or a counteroffer?
-
As risk management officer at your firm, you are in charge of analyzing the data on personal injury claims filed in the recent past is below. A histogram of the data is mound shaped and roughly...
-
According to Managing Change Control to Comply with FDA and EU Regulations article, In the manufacturing environment, change refers to any modification in: Answer:
-
Global Corruption Barometer - Nations Results: Mexica on Over the past two years how has the level of corruption in this country / territory changed?
-
1. Consider 21 bit VPN Ox 000D2B and page offset Ox 14C. Assuming a 2KB page size, 2 byte page table entries, and 14 bit PPNs, answer the following: (a) What is the capacity of the virtual memory?...
-
Derive the logic expressions to generate the signals PC_select and INC_select shown in Figure 5.20, taking into account the actions needed when executing the following in- structions: Branch: All...
-
Anatomy of Glomerulus- Practice 1 4 (b) (a) 2.
-
If the joint cost function for two products is C(x, y) = xy2 + 1 dollars (a) Find the marginal cost (function) with respect to x. (b) Find the marginal cost with respect to y.
-
Use an online library service to find basic business research studies that report a response rate or number of respondents compared to number of contacts.You may wish to consult journals like the...
-
What is the entropy or pseudo R 2 ?
-
What would the equation be for any particular observation response as a result of some three-factor factorial design?
-
For the Lyman series, what is the wavelength of the line with the second longest wavelength? Would it be visible to the human eye?
-
In 1924 French theorist Louis de Broglie (1892 1987, Nobel laureate in physics 1929) proposed that matter has a wavelike nature expressed by \(\lambda=\frac{h}{m v}\). Show that his relation agrees...
-
This problem presents an example of the Correspondence Principle. Suppose that the electron in hydrogen is traveling in a circular orbit with quantum number \(n\) and makes a transition to \(n+1\),...
Study smarter with the SolutionInn App