Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need java code. Work on the rest, one is allready done. . TwoDimArray code Animation of Multidimensional Programming Activity Lab Objectives - Be able

I need java code. Work on the rest, one is allready done. image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

TwoDimArray code

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Animation of Multidimensional Programming Activity Lab Objectives - Be able to declare two-dimensional arrays - Be able to pass two-dimensional amays to methods - Be able to return a two-dimensional amay from methods - Be able to process a two-dimensional array in a Java Method - Be able to work with individual rows and columns in a two-dimensional array Introduction Writing methods that take multi-dimensional amays as parameters and/or return multidimensional arrays is similar to working with single-dimensional amays. The syntax for a method that accepts a two-dimensional array as a parameter is as follows: return Type methodName( arrayType arrayParameterName) The syntax for a method that retums a two-dimensional array is the following: return Array Type []] methodName( array Type [ ][ ] arxayParameterName) In this Lab, you will work with a 4-row, 20-column, two-dimensional array of integers. You will write methods that perform the following operations: 1. Fill the 2-D array with random numbers between 50 and 80 . 2. Print the array. 3. Set every amay element of a given row to a specified value. The value is a parameter of a method. 4. Find the minimum value in a given column of the array. The column is a parameter of a method. 5. Count the number of elements of the array having a specified value. The value is a parameter of a method To visualize how the two-dimensional array is working, your result will animate a bar graph. The Code for the bar graph is provided to you as BarChart.java. So, the framework for this lab will animate your algorithm, which will support you in checking the accuracy of your Java program. I ab Instructinns Lab Instructions The source files required to complete this activity has been provided. TwoDimArrayPractice java and BarChart.java) Copy both the files to a folder in your computer. It is important that both the files stay in the same folder. Open the TwoDimAmayPractice.java source file. For your convenience, the sample code for task number 1 has been provided under comment 1 for the fillvalues 0 method. You may use this as a model for completing the remaining four tasks. You will need to complete th rest of the four tasks in four other methods. In each one of these four remaining tasks, you will fill in the code for a method that will manipulate an existing array of 4 rows and 20 columns. You do not need to instantiate the two-dimensional array. That has been done for you. SAMPLE OUTPUT: Following shows a sample output from the fillValues() method. ||l|| |l||||||||||l|l| Ilililillinilliul IIIl|l|l|lin|liul|l| Task \#1 Print Array to Console. 1. For printing array to console, please make a complete implementation of the method: public void printArray() This method is under comment 2 . 2. For console printing, elements are separated by a space. The instance variable named intArray is the integer array to be printed. 3. To animate the algorithm, put this method call as the last element in your inner for loo animate( row, column ); Here row is the index of the array's current row, and column is the index of the array's current column. OUTPUT: Following shows the screen capture of the required output from the printArray () method. Row 3 6858656074746658605565785870756974606667 83 Message (i) Array printed OK Task \#2 Set All Elements in A Row to A Specilied Value 1. This is under comment 3. Please, implement the setValues(int value, int row ) method that sets all the elements in the specified row to a specified value. 2. The instance variable named intArray is the integer amay. 3. To animate the algorithm, put this method call as the last element in your forloop animate( row, column ); Here row is the index of the array's current row and column is the index of the array's current column. OUTPUT: Following shows the screen capture of the required output from setValues (65,2). Task #3 Find Minimum Value in the Specified Column 1. Implement the method public int findMinimum( int column ) that finds the minimum value in the specified column. 2. Again, the instance variable named intArray is the integer array 3. To animate the algorithm, put this method call as the last element in your for loop animate( row, column ); Here row is the index of the array's current row and column is the index of the array's current column 4. Notice that a dummy retum statement (retum 0 ) is provided at the end of public int find Iinimum(int column) method so that the source code will compile in its present state. In this way, you can write and test each method separately, which is known as the step-wise refinement. When you are ready to write the public int findMinimum( int column ) method, just replace the dummy return statement with the appropriate retum statement for the method. Following shows screen shot of the output for findMinimum(3). In column 3, you found a minimum value of 60 This is correct Task \#4 Find Frequency of a Given Value in the Array 1. Implement the method public int countFound(int value ) that counts the number of times a given value is found in the array. 2. The instance variable named intArray is the integer amray. 3. To animate the algorithm, put this method call as the last element in your for loop animate(row, column ); Here row is the index of the array's current row and column is the index of the array's current column 4. Notice that a dummy retum statement (retum 0) is provided at the end of public int countFound(int value) method so that the source code will compile in its present state. In this way, you can write and test each method separately using the step-wise refinement. When you are ready to write the public int countFound(int value) method, just replace the dummy retum statement with the appropriate return statement for the method. OUTPUT: The two java files (TwodimArrayPrac. java and Barchart. java) running under the same project will animate your algorithm so that you can visually watch your code work. For this to happen, make sure that your single or nested for loops call the method animate. The arguments that you send to amimate are not always the same and the location of the call to animate will differ depending on the task you are coding. Since the values in the two-dimensional aray are randomly generated, the values will be different each time the program runs. To test any of the methods that you have implemented, please click on the appropriate button. Task #5 - Upload to GitHub 1. Upload both files to GitHub in a directory named CMSC203_Lab4. Deliverables: Submit the following files: Screen shot with "Find Minimum" button selected and the result confirmed in an Alert 60 Screenshot of your GitHub account with submitted Lab4 files Both * java files submit on GitHub and Blackboard, Lab4 BarChart - Notepad File Edit Format View Help * BarChart Code */ import java. awt. Graphics; import java. awt. Image; import java. awt.image. * import javax. swing. JFrame; import java. awt. Color; public class BarChart implements Image0bserver public static final int XMAX =400; public static final int XSTART =60; public static final int [] YMAX ={220,320,420,520}; I/ hard code an array of 4 colors private Color [] colors ={ Color. BLUE, new Color (150,150,0), private int [] [] data; Color.DARK GRAY, Color.MAGENTA }; private int barsize; private int xstart; private int activity =5 private int count =0; private int studentresult; private int exactFrequencycount; private int exactminimum; private int key; private boolean checkNewValues; public Barchart ( ) \{\} public Barchart ( int [] [] dArray) File Edit Format View Help public void setstudentResult ( int newstudentResult) ) \{ studentResult = newStudentResult; \} Dublic void setkev ( int newkev) File Edit Format View Help BarChart - Notepad File Edit Format View Help drawNewValue ( index1, index 2,g ); break; case(3) : 1/ find the minimum in a row drawMinimum( index1, index 2,g ); break; case(4) : // find the frequency of a value drawFrequency ( index1, index 2 , key, g ); break; \} \} public void draw ( Graphics g) \{ // Draws the original array in 4 colors for ( int i=0;i data [i][ index2 ]) 3 minimum = data [i][ index2 ]; return minimum; \} public void drawFrequency ( int index 1 , int index 2 , int value, Graphics g ) I/ called to count frequency of a value I/ index1 must be less than 4 1/ index2 must be less than 20 R. setColor ( Color. BLUE ): BarChart - Notepad File Edit Format View Help g. setColor (Color.BLUE ) g.drawString( "Your current frequency count: " + studentResult, 25, 110); exactFrequencyCount = findExactFrequencyCount ( index1, index2, value); g.drawString( "Correct current frequency count: " + exactFrequencyCount, 25, 130); g.setColor (Color.RED) for ( int i=0;i80) \{ try \{ answer =30 ptionPane. ShowInputDialog ( null, "Enter a value between 50 and 80"; ; if (answer ! = null) \{ key = Integer parseInt ( answer ) goodinput = true; ? else \{ goodinput = false; break; \} 31 catch (Exception e) \{\} \} if ( goodinput) \{ goodinput = false; while ( goodinput rowselected 3 ) try \{ answer = J0ptionPane. showInputDialog ( nu11, "Enter a row number between 0 and 3" ); if ( answer ! = null) rowselected = Integer . parseInt ( answer ) goodinput = true; "TwoDimArrayPractice - Notepad File Edit Format View Help "TwoDimArrayPractice - Notepad File Edit Format View Help "TwoDimArrayPractice - Notepad File Edit Format View Help File Edit Format View Help break; \} enableButtons (; \} public static int getCurrent1( ) \{ return current1; public static int getcurrent2( ) \{ return current2; \} public static int getcounter ( ) \{ return counter; \} public static int [] [] getArray ( ) return intArray; j Edit Format View Help "TwoDimArrayPractice - Notepad File Edit Format View Help File Edit Format View Help *TwoDimArrayPractice - Notepad File Edit Format View Help ? File Edit Format View Help Animation of Multidimensional Programming Activity Lab Objectives - Be able to declare two-dimensional arrays - Be able to pass two-dimensional amays to methods - Be able to return a two-dimensional amay from methods - Be able to process a two-dimensional array in a Java Method - Be able to work with individual rows and columns in a two-dimensional array Introduction Writing methods that take multi-dimensional amays as parameters and/or return multidimensional arrays is similar to working with single-dimensional amays. The syntax for a method that accepts a two-dimensional array as a parameter is as follows: return Type methodName( arrayType arrayParameterName) The syntax for a method that retums a two-dimensional array is the following: return Array Type []] methodName( array Type [ ][ ] arxayParameterName) In this Lab, you will work with a 4-row, 20-column, two-dimensional array of integers. You will write methods that perform the following operations: 1. Fill the 2-D array with random numbers between 50 and 80 . 2. Print the array. 3. Set every amay element of a given row to a specified value. The value is a parameter of a method. 4. Find the minimum value in a given column of the array. The column is a parameter of a method. 5. Count the number of elements of the array having a specified value. The value is a parameter of a method To visualize how the two-dimensional array is working, your result will animate a bar graph. The Code for the bar graph is provided to you as BarChart.java. So, the framework for this lab will animate your algorithm, which will support you in checking the accuracy of your Java program. I ab Instructinns Lab Instructions The source files required to complete this activity has been provided. TwoDimArrayPractice java and BarChart.java) Copy both the files to a folder in your computer. It is important that both the files stay in the same folder. Open the TwoDimAmayPractice.java source file. For your convenience, the sample code for task number 1 has been provided under comment 1 for the fillvalues 0 method. You may use this as a model for completing the remaining four tasks. You will need to complete th rest of the four tasks in four other methods. In each one of these four remaining tasks, you will fill in the code for a method that will manipulate an existing array of 4 rows and 20 columns. You do not need to instantiate the two-dimensional array. That has been done for you. SAMPLE OUTPUT: Following shows a sample output from the fillValues() method. ||l|| |l||||||||||l|l| Ilililillinilliul IIIl|l|l|lin|liul|l| Task \#1 Print Array to Console. 1. For printing array to console, please make a complete implementation of the method: public void printArray() This method is under comment 2 . 2. For console printing, elements are separated by a space. The instance variable named intArray is the integer array to be printed. 3. To animate the algorithm, put this method call as the last element in your inner for loo animate( row, column ); Here row is the index of the array's current row, and column is the index of the array's current column. OUTPUT: Following shows the screen capture of the required output from the printArray () method. Row 3 6858656074746658605565785870756974606667 83 Message (i) Array printed OK Task \#2 Set All Elements in A Row to A Specilied Value 1. This is under comment 3. Please, implement the setValues(int value, int row ) method that sets all the elements in the specified row to a specified value. 2. The instance variable named intArray is the integer amay. 3. To animate the algorithm, put this method call as the last element in your forloop animate( row, column ); Here row is the index of the array's current row and column is the index of the array's current column. OUTPUT: Following shows the screen capture of the required output from setValues (65,2). Task #3 Find Minimum Value in the Specified Column 1. Implement the method public int findMinimum( int column ) that finds the minimum value in the specified column. 2. Again, the instance variable named intArray is the integer array 3. To animate the algorithm, put this method call as the last element in your for loop animate( row, column ); Here row is the index of the array's current row and column is the index of the array's current column 4. Notice that a dummy retum statement (retum 0 ) is provided at the end of public int find Iinimum(int column) method so that the source code will compile in its present state. In this way, you can write and test each method separately, which is known as the step-wise refinement. When you are ready to write the public int findMinimum( int column ) method, just replace the dummy return statement with the appropriate retum statement for the method. Following shows screen shot of the output for findMinimum(3). In column 3, you found a minimum value of 60 This is correct Task \#4 Find Frequency of a Given Value in the Array 1. Implement the method public int countFound(int value ) that counts the number of times a given value is found in the array. 2. The instance variable named intArray is the integer amray. 3. To animate the algorithm, put this method call as the last element in your for loop animate(row, column ); Here row is the index of the array's current row and column is the index of the array's current column 4. Notice that a dummy retum statement (retum 0) is provided at the end of public int countFound(int value) method so that the source code will compile in its present state. In this way, you can write and test each method separately using the step-wise refinement. When you are ready to write the public int countFound(int value) method, just replace the dummy retum statement with the appropriate return statement for the method. OUTPUT: The two java files (TwodimArrayPrac. java and Barchart. java) running under the same project will animate your algorithm so that you can visually watch your code work. For this to happen, make sure that your single or nested for loops call the method animate. The arguments that you send to amimate are not always the same and the location of the call to animate will differ depending on the task you are coding. Since the values in the two-dimensional aray are randomly generated, the values will be different each time the program runs. To test any of the methods that you have implemented, please click on the appropriate button. Task #5 - Upload to GitHub 1. Upload both files to GitHub in a directory named CMSC203_Lab4. Deliverables: Submit the following files: Screen shot with "Find Minimum" button selected and the result confirmed in an Alert 60 Screenshot of your GitHub account with submitted Lab4 files Both * java files submit on GitHub and Blackboard, Lab4 BarChart - Notepad File Edit Format View Help * BarChart Code */ import java. awt. Graphics; import java. awt. Image; import java. awt.image. * import javax. swing. JFrame; import java. awt. Color; public class BarChart implements Image0bserver public static final int XMAX =400; public static final int XSTART =60; public static final int [] YMAX ={220,320,420,520}; I/ hard code an array of 4 colors private Color [] colors ={ Color. BLUE, new Color (150,150,0), private int [] [] data; Color.DARK GRAY, Color.MAGENTA }; private int barsize; private int xstart; private int activity =5 private int count =0; private int studentresult; private int exactFrequencycount; private int exactminimum; private int key; private boolean checkNewValues; public Barchart ( ) \{\} public Barchart ( int [] [] dArray) File Edit Format View Help public void setstudentResult ( int newstudentResult) ) \{ studentResult = newStudentResult; \} Dublic void setkev ( int newkev) File Edit Format View Help BarChart - Notepad File Edit Format View Help drawNewValue ( index1, index 2,g ); break; case(3) : 1/ find the minimum in a row drawMinimum( index1, index 2,g ); break; case(4) : // find the frequency of a value drawFrequency ( index1, index 2 , key, g ); break; \} \} public void draw ( Graphics g) \{ // Draws the original array in 4 colors for ( int i=0;i data [i][ index2 ]) 3 minimum = data [i][ index2 ]; return minimum; \} public void drawFrequency ( int index 1 , int index 2 , int value, Graphics g ) I/ called to count frequency of a value I/ index1 must be less than 4 1/ index2 must be less than 20 R. setColor ( Color. BLUE ): BarChart - Notepad File Edit Format View Help g. setColor (Color.BLUE ) g.drawString( "Your current frequency count: " + studentResult, 25, 110); exactFrequencyCount = findExactFrequencyCount ( index1, index2, value); g.drawString( "Correct current frequency count: " + exactFrequencyCount, 25, 130); g.setColor (Color.RED) for ( int i=0;i80) \{ try \{ answer =30 ptionPane. ShowInputDialog ( null, "Enter a value between 50 and 80"; ; if (answer ! = null) \{ key = Integer parseInt ( answer ) goodinput = true; ? else \{ goodinput = false; break; \} 31 catch (Exception e) \{\} \} if ( goodinput) \{ goodinput = false; while ( goodinput rowselected 3 ) try \{ answer = J0ptionPane. showInputDialog ( nu11, "Enter a row number between 0 and 3" ); if ( answer ! = null) rowselected = Integer . parseInt ( answer ) goodinput = true; "TwoDimArrayPractice - Notepad File Edit Format View Help "TwoDimArrayPractice - Notepad File Edit Format View Help "TwoDimArrayPractice - Notepad File Edit Format View Help File Edit Format View Help break; \} enableButtons (; \} public static int getCurrent1( ) \{ return current1; public static int getcurrent2( ) \{ return current2; \} public static int getcounter ( ) \{ return counter; \} public static int [] [] getArray ( ) return intArray; j Edit Format View Help "TwoDimArrayPractice - Notepad File Edit Format View Help File Edit Format View Help *TwoDimArrayPractice - Notepad File Edit Format View Help ? File Edit Format View Help

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

3. What are potential solutions?

Answered: 1 week ago

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago