Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a method that, accepting a 2-dimensional array of type char, can produce a box and display each character drawn from the array within.

 imageimageimageimage

Create a method that, accepting a 2-dimensional array of type char, can produce a box and display each character drawn from the array within. You must meet the submission deadline and must demo your code on your assigned period to get your marks. Grades: 5% of your final course mark Deadline Submission (September 28th, 11:59 PM.) Demo on your next lab period (September 30, 2022). // Important marking code: if (!submission || Idemo || lateSubmission) { grade = 0; 3 Lab 2-2D Arrays (2).pdf of 5 Q + File | C:/Users/ACER/Downloads/Lab%202-2D%20Arrays%20(2).pdf Type here to search CD Page view A Read aloud Steps Step 1. Create a New Project In this case, there must be only one class file, named Lab2. Case matters, so it may not be "lab2". If you wish to put it in a package, that package must be named "lab2". The main method is provided for you, and you must use it as-is. You may not modify it, except you may change the format and comments. Leave the code itself alone. public static void main(String[] args) { TAdd text This code will call your method, and pass it a 2D array of chars that it has created, of unknown size. Feel free to copy and paste it into your project. Lab2 thisLab = new Lab2 (); int counter=97; //ASCII lowercase a. Random myrand = new Random(); //For random number generation. } int rows = myrand.nextInt (5) +1; char[] [] myArray = new char[rows] []; //Creation of random-height 2D array. } Draw for (int i=0;i 4 Lab 2-2D Arrays (2).pdf of 5 Q + File | C:/Users/ACER/Downloads/Lab%202-2D%20Arrays%20(2).pdf Type here to search O CD Page view A Read aloud Step 2. Method printSquare(char[][] charArray) Create a new method named printSquare, which accepts a 2-dimensional array of chars. Your code must go through the array, creating squares and printing the contents of each cell of the array. As the provided main method generates a different array each time, you will get different results each time you run the code. A few sample runs are below: +-----+ 1 1 I I T I a g 1 I I I h | | d i e f TAdd text Draw Highlight 9C Mostly cloudy Erase {" 67 4x ENG @ 0 11:38 PM 9/28/2022 X 4 Lab 2-2D Arrays (2).pdf of 5 Q + + File | C:/Users/ACER/Downloads/Lab%202-2D%20Arrays%20(2).pdf Type here to search O I A few sample runs are below: I __ a CD Page view bl f I Ia I --- --- A g b --- --- h e A Read aloud T Add text Your code will not "know" any of the dimensions of the array, and must get that information from the array itself, line by line. You will find the last handful of pages in Week 1's lecture notes very helpful for this. Under no circumstances can you assume anything about the array's size. It might even be 0! I may sneak in arrays of different sizes than is provided in main. Your code must be able to handle it. If a given row is zero, print nothing. Don't produce any output at all and continue with the next row. Draw Highlight 9C Mostly cloudy 0 a -> Erase {" 67 4x ENG @ 0 11:38 PM 9/28/2022 X 5 Lab 2-2D Arrays (2).pdf of 5 Q + File | C:/Users/ACER/Downloads/Lab%202-2D%20Arrays%20(2).pdf Type here to search O JU! CD Page view Your code must figure out the maximum width from the array itself and may make no assumptions about its size. I should be able to use any-sized array with this code. A Read aloud Step 3. Submit your Code In the main Brightspace shell, turn in your code. Submit the java file you wrote, in a zip file ONLY. .7z, .rar or other compression formats will result in a penalty. [T] Add text Step 4. Demo your Code In your lab next week, have your code ready to run. I will call upon you in random order. Final Thoughts Few Suggestions In your project, all array sizes must be drawn from the array itself. You may assume nothing about the size of the array at all. I should be able to use an array of any size with your method. Marking Scheme Think of this as a sequence of events. If you confused by the code, show me your thinking. In plain English, write out the operations, step by step, that you would do to solve this problem. Do pay attention to the filename requirements. Your class must be "Lab2". Do not forget your comments! These are easy marks. You can quickly format your code in Eclipse with CTRL+SHIFT+F. It's much easier to debug formatted code. Check Rubric H Draw Highlight 9C Mostly cloudy o a -> Erase {" 67 4x ENG @ 0 11:38 PM 9/28/2022 X

Step by Step Solution

3.33 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

Heres a solution to meet the requirements import javautilRandom public class Lab2 public static void ... 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

Data Modeling and Database Design

Authors: Narayan S. Umanath, Richard W. Scammel

2nd edition

1285085256, 978-1285085258

More Books

Students also viewed these Programming questions

Question

What is the source of magnetic force?

Answered: 1 week ago

Question

Describe various data types associated with attributes.

Answered: 1 week ago