Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java I want to see the how the classes sorted under the package Continue working on the Table class from the project lab2 created in

Java I want to see the how the classes sorted under the package

Continue working on the Table class from the project lab2 created in the lab.

a. Constructor

Add a constructor with a single parameter n, where the maze is initialized as a square array of n-by-n. Call the function init with the appropriate parameters.

b. Shrink

Write another class method called shrink similar to expand but where the new size of the table is actually smaller than the old one. It should have the same parameters as the function expand, but the for loop should be based on the new number of rows, and the number of elements to be copied in the call to arraycopy should be equal to the new number of columns. Add an extra test for it in the main.

c. Search

Add two functions searchFirst and searchLast, that search for the first and last occurrence of a specific value in the maze, and output the coordinates if they find it, and a message saying that it's not there if not. In the main, add a call to each of these functions with the value 1.

d. (optional, 3 extra credit points) Pretty Output

Write a method called prettyOutput for the maze where you output it in a format that is easier to visualize. For this, print a border around the table, like a + in each corner, a row of minuses above and below the table, and a | at the beginning and at the end of each row. Then when you print the elements, check if the value is equal to 0, and if it is, print a couple of spaces, if it's equal to 1, then print a * character followed by a space, and if it's equal to 2, print a period (.) followed by a space.

For example, if the raw output of the table gives us

1 0 0 1 0 0 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 1 1 

then the pretty output of the table should be

+----------+ |* * | | * | |* * | | * | | * * | +----------+ 

Hint. For this exercise, the maze itself will not be changed. This is not about replacing the numbers in the table with characters. The numbers remain as they are.

For the top and bottom borders, you have to start by printing a "+" string. Then you need a loop going over the number of columns, where for each element you output the string "--". Then after the loop you need another "+".

For the part in between, you need a couple of nested loops, like in the function rawOutput. For each element of the maze, test if it is 0, and print the string " " in that case, and so on. You also need to print "|" before and after each row for the vertical borders.

e. (optional, 3 extra credit points). Border

Write a method makeBorder that creates a border in the table made of the value 2. For this, use the function Arrays.fill() to fill in the first (index of 0) and last (index of rows-1) rows with the value 2. Then for all the rows in between, assign to the first (0) and last (columns-1) elements the value 2. You'll need a loop for the second part.

In the main, after expanding the array by calling the method from the lab, call the function makeBorder, then pretty output the array to see the result.

For example, if you were to call the function makeBorder on a maze that was just printed, the raw output would give you

2 2 2 2 2 2 0 1 0 2 2 1 0 0 2 2 1 0 0 2 2 2 2 2 2 

then the pretty output of the table should be

+----------+ |. . . . . | |. * . | |. * . | |. * . | |. . . . . |

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

=+2. What research methodologies would be most effective?

Answered: 1 week ago