Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Programming language: JAVA, (Eclips) Given the skeleton code for class Pattern, complete the methods that are required to make the patterns as shown in the
Programming language: JAVA, (Eclips)
Given the skeleton code for class Pattern, complete the methods that are required to make the patterns as shown in the section of sample output. Write 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. Each print method is responsible for printing a pattern.
A skeleton code for class Pattern:
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
2. Sample output: 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. Two 45 degree diagonals pass through a point (8, 18): 1 1 1 1 1 1 1 1 1 1 1 1 eee1 1 01 1 1 01 1 1 1 1 1 1 1 1 eeeeeeeee1 1 eeeeeeee1 1 eeeeeee1 1 eeeeee1 1 A rectangle with a half-sized rectangular hole: 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 A rectangle with a sin curve: 1 1 1 1 1 1 1 11 1 11 0 1 1eeeeeeeeeeeeeeee1 01 11 eee1 1 eeee1 eeeee1 eeeeee1 eeeeee1eeee1 eeeeeee1 1 1 1 2. Sample output: 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. Two 45 degree diagonals pass through a point (8, 18): 1 1 1 1 1 1 1 1 1 1 1 1 eee1 1 01 1 1 01 1 1 1 1 1 1 1 1 eeeeeeeee1 1 eeeeeeee1 1 eeeeeee1 1 eeeeee1 1 A rectangle with a half-sized rectangular hole: 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 A rectangle with a sin curve: 1 1 1 1 1 1 1 11 1 11 0 1 1eeeeeeeeeeeeeeee1 01 11 eee1 1 eeee1 eeeee1 eeeeee1 eeeeee1eeee1 eeeeeee1 1 1 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started