Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 < rows; i++){ for (int j = 0; j < cols; j++){ if( //Meet certain conditions ) p[i][j] = 1; else p[i][j] = 0; } } } //This method prints a 2D pattern stored in 2D array p public static void print(int [][] p) { } //Add more methods here }

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

Students also viewed these Databases questions

Question

What are the need and importance of training ?

Answered: 1 week ago

Question

What is job rotation ?

Answered: 1 week ago