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
-
K The trend analysis report of Basic, Inc. is given below (in millions): Net income 2025 $710 2024 $608 2023 2022 2021 $459 $406 $370 Using 2021 as the base year, the net income in 2024 is OA. 91.9%...
-
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...
-
Below is the Employee Earnings Record for Ally Murner of Cosmic Comics. Record her earnings on the September 12 pa.
-
Explain the relationship between consumer learning requirements and adoption and diffusion of innovations.
-
On March 1, 20xx, Carmel Corporation began operations with a charter from the state that authorized 100,000 shares of $4 par value common stock. Over the next quarter, the firm engaged in the...
-
The transactions that follow took place at the Cedar Hill Sports Arena during September 2016. This firm has indoor courts where customers can play tennis for a fee. It also rents equipment and offers...
-
Una persona realiza un viaje por un sendero durante 4 das. Cada uno de los das caminaba un 20% que la distancia del da anterior. En total recorri 27 kilmetros. Cul es la distancia que camin esta...
-
Thaarugo,inc, produces a GPS device that is becoming popular in parts of Scandinavia. When Thaarugo produces one of these, a printed circuit board (PCB) is used and it is populated with several...
-
10 1 pts In the experiment examining covert consciousness, which of the following is a conclusion you could draw from the results? People in comas rarely recover fully. People who are in coma
-
Cause of the Wars of Independence in Colonial Spanish create a presentation highlight key points , also please add citations and refences
-
Because of a new product line, your company's sales over the last few months have increased significantly. As a result, the amount of cash held by the company has increased to levels never...
-
assume the direct cost of manufacturing is 50% of sales, 30% is attributed to employee salaries, and profit accounts in 20%. further assume through better planning we can reduce the cost of...
-
A middle manager in Malaysia is about to be stationed for two years to Canada. Canada has relatively low power distance whereas employees in Malaysia have quite high power distance. Advise the...
-
How does the use of computational methods and density functional theory (DFT) in catalysis research enhance our ability to predict catalytic behavior, and what are the limitations of these...
-
Calculate r for a 4 year investment at 13% p.a. where the interest is compounded monthly( in the format 0.0000).
-
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?
-
The amount that will be accumulated in the future when a series of payments is invested and accrues interest until the future time. True/false
-
The amount that will be accumulated in the future when one amount is invested at the present time and accrues interest until the future time. True/false
-
Credit Terms You receive an invoice from a supplier for $5,000 on January 1 with terms 3/15, net 30. If you pay between January 1 and January 16, how much must you pay? If you pay after January 16,...
Study smarter with the SolutionInn App