Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called Lab7a and in it implement all of the methods below. Also, write a main method with test calls to all of

image text in transcribedimage text in transcribed

Create a class called Lab7a and in it implement all of the methods below. Also, write a main method with test calls to all of these methods. 1. Write a function called median, that takes as parameter a full, sorted array of doubles and returns the median of the list. For a sorted list of odd length, the median is the middle value. For a sorted list of even length, the median is the average of the two middle values. Make an example function call in your main. 2. Write a function called is Sorted that takes an array of doubles as a parameter and returns true if the list is in sorted (non-decreasing) order and returns false otherwise. Make an example function call in your main. 3. Write a function called find Common that takes three arrays of positive integers as parameters. The first two array parameters are filled with ints. Fill the third array parameter with all the values that are uniquely in common from the first two arrays and the rest of the array with zeros. For example: (a) a1[] contains: 3 8 5 658 92 (b) a2[] contains: 5 15 4 673 9 11 9 3 12 13 14 9 5 3 13 (c) common[] should contain: 3 5690000 4. Write a function called rotateRight that takes an array of integers as an argument and rotates values in the array one to the right (i.e., one forward in position), shifting the value at the end of the array to the front. For example, if the array called list stores [3, 8, 19, 7] before the function is called, it should store (7, 3, 8, 19] after the function is called. Another call on rotate Right would leave the list as [19, 7, 3, 8]. Another call would leave the list as [8, 19,7, 3] 5. Write a function count that takes an array of integers and a target value as parameters and returns the number of occurrences of the target value in the array. For example, if an array called list stores the sequence of values [3, 5, 2, 1, 92, 38, 3, 14, 5, 73] then the following call int n = count(list, 3); would return 2 because there are 2 occurrences of the value 3 in the list. 6. Write a function called stretch that takes an array of integers as an argument, and returns a new array twice as large as the original that 'replaces' every integer from the original list with a pair of integers, each half the original, and then returns it. If a number in the original list is odd, then the first number in the new pair should be one higher than the second so that the sum equals the original number. For example, suppose a variable called list stores the sequence of values [18, 7, 4, 24, 11). The number 18 is stretched into the pair (9,9), the number 7 is stretched into (4,3), the number 4 is stretched into (2, 2), the number 24 is stretched into (12, 12) and the number 11 is stretched into (6,5). Thus, the call: stretch(list); should replace list with the following list which is twice the length of the original: [9,9,4, 3, 2, 2, 12, 12, 6, 5] Create a class called Lab7b and in it implement all of the methods below. Also, write a main method with test calls to all of these methods. Don't forget to turn in your file to Canvas before the end of the lab today. 1. int[][] random(int N, int start, int end) returns an N-by-N matrix of random integers ranging from start to end; 2. int rowSum(int[][] a, int i) returns the sum of the elements in row i of the 2-D array a; 3. int colSum(int[][] a, int j) returns the sum of the elements in column of the 2-D array a; 4. boolean isSquare(int[] [] a) returns true if the 2-D array a is square (i.e. the number of rows and columns are the same); 5. boolean isLatin(int[][] a) returns true if the 2-D array a is a Latin square (i.e. an n-by-n matrix such that each row and each column contains the values from 1 through n with no repeats); 6. main(String[] args): the main method should test each method above on five randomly generated matrices and also these ones: int[][] allneg = { {-10,-12,-3}, {-4,-5,-6,-8}, {-7,-8} }; int[][] nonsquare ={ {1,2,3}, {4,5}, {6,7,8,9} }; int[][] latin = { {1,2,3}, {2,3,1}, {3,1,2} }; int[][] notlatin = { {2,1,3}, {2,3,1}, {3,1,2} }; 7. Write a program Shift Numbers.java that takes integer M as the number of both rows and columns for your 2D array. Create the same exact following 2D array. Note: The borders are produced at the time of printing. You also need to shift the numbers for each row of the 2D array as displayed below: |1|23|4151 21314151 |3|4|5|1|2| 14/5/1/2131 51213141 +-+-+-+-+-+

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_2

Step: 3

blur-text-image_3

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions