Question: Use the skeleton code for class Pattern to complete the methods the generate the patterns as shown in the section of the sample output. Create

  1. Use the skeleton code for class Pattern to complete the methods the generate the patterns as shown in the section of the sample output. Create a method for each pattern. In addition, you need to add a print method to print these patterns.

    Each of these methods takes a 2D array variable as input parameter, generates a pattern and stores back into the 2D array variable. The print method is just responsible for printing a pattern.

    A skeleton code for class Pattern as below:

    import java.util.Scanner; public class Pattern { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter the height and width of a rectangle: "); int height = input.nextInt(); //The height of the rectangle int width = input.nextInt(); //The width of the rectangle System.out.println("Enter the row and column indice for a point through which two 45 degree diagonals pass: "); int r = input.nextInt(); //The row index int c = input.nextInt(); //The column index int rows = height + 1; //The number of rows of the rectangle int cols = width + 1; //The number of columns of the rectangle int [][] a = new int[rows][cols]; //Create a 2D array with size of rows by cols System.out.println(" A rectangle with 0's in the upper triangle and 1's in the lower triangle:"); createRectangle(a); print(a); System.out.println(" Two 45 degree diagonals pass through a point (" + r + ", " + c + "):"); createTwoDiagonals(a, r, c); print(a); System.out.println(" A rectangle with a half-sized rectangular hole:"); createRectangularHole(a); print(a); System.out.println(" A rectangle with a circular hole:"); createCircularHole(a); print(a); System.out.println(" A rectangle with a sin curve:"); createSinCurve(a); print(a); } //This method takes an allocated 2D array and create a 2D pattern and store into the array. public static void createRectangularHole(int [][] p) { int rows = p.length; int cols = p[0].length; int h = rows - 1; int w = cols - 1; for (int i = 0; i  Use the skeleton code for class Pattern to complete the methodsthe generate the patterns as shown in the section of the sample

Enter the height and width of a rectangle: 20 34 Enter the row and column indice for a point through which two 45 degree diagonal s pass: 8 18 A rectangle with O's in the upper triangle and i's in the lower triangle: Read this handout for mathematical formula for this question. eeeeee1 1 1 1 1 1 1 1 1 1 1 1 1111111 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1111111111111111 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1111111111111111111 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeee 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Read this handout for mathematical formula for this question. Two 45 degree diagonals pass through a point (8, 18): 1 1 1 11 11 eeee1e0o1 eeeee Two 45 degree diagonals pass through a point (8, 18): 1 10 1 1 1 1 11 11 1 eee1 1 1 1 1 1 1 1 eeeeee 1 1 000 A rectangle with a half-sized rectangular hole: eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 11 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 A rectangle with a circular hole. The radius of the hole = 1/4 max(width, height of the rectangle). 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 A rectangle with a sin curve: eee 0e111100 1 eeee1eeeeee 1 1 1 1 1 1 eee1 eeeeeeeeeeee1 eeeee1eeeeee1 1 1 1 1 11 Enter the height and width of a rectangle: 20 34 Enter the row and column indice for a point through which two 45 degree diagonal s pass: 8 18 A rectangle with O's in the upper triangle and i's in the lower triangle: Read this handout for mathematical formula for this question. eeeeee1 1 1 1 1 1 1 1 1 1 1 1 1111111 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1111111111111111 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1111111111111111111 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeee 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Read this handout for mathematical formula for this question. Two 45 degree diagonals pass through a point (8, 18): 1 1 1 11 11 eeee1e0o1 eeeee Two 45 degree diagonals pass through a point (8, 18): 1 10 1 1 1 1 11 11 1 eee1 1 1 1 1 1 1 1 eeeeee 1 1 000 A rectangle with a half-sized rectangular hole: eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eeeeeeeee1 1 1 11 1 1 eeeeeeeee1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 A rectangle with a circular hole. The radius of the hole = 1/4 max(width, height of the rectangle). 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 A rectangle with a sin curve: eee 0e111100 1 eeee1eeeeee 1 1 1 1 1 1 eee1 eeeeeeeeeeee1 eeeee1eeeeee1 1 1 1 1 11

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!