2.2 7.7 8.8 2.2 9.9 7.7 4.4 8.8 6.6 7. A method named addRow that takes two parameters: the first is a two-dimensional array of doubles, and the second is a one-dimensional array of doubles. The method must return a new two-dimensional array of doubles that results from adding the second parameter (one-dimensional array) as a last row to the first parameter (two-dimensional array). The following implementation forms the new array by making it point to the same rows of the 2-dimensional array and the 1-dimensional array: public static double[][] addRow(double [] array, double[]row)[ double[][] newArray = new double[array.length+1][]: for(int i=0; i

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
1.12.2 7.7 8.8 2.2 9.9 7.7 4.4 8.8 6.6 7. A method named addRow that takes two parameters: the first is a two-dimensional array of doubles, and the second is a one-dimensional array of doubles. The method must return a new two-dimensional array of doubles that results from adding the second parameter (one-dimensional array) as a last row to the first parameter (two-dimensional array). The following implementation forms the new array by making it point to the same rows of the 2-dimensional array and the 1-dimensional array: public static double[][] addRow(double [] array, double[]row)[ double[][] newArray = new double[array.length+1][]: for(int i=0; i
Write the following methods in vour class:
1. A method named duplicatesCount that takes an array of double values and returns the
count of numbers duplicated (i.e. numbers that appear more than once) in the array,
regardless of how many times each is duplicated.
For example, if the array {1.1, 9.9, 4.4, 3.3, 3.3, 9.9, 2.2, 6.6, 7.7, 1.1, 9.9} is passed to
this method, it must return 3 since the numbers 1.1, 9.9, and 3.3 appear more than once
in the array.
2. A method named commonCount that takes two arrays of double values and returns the
count of numbers that are common between the two arrays. If an element appears more
than once it must not be counted twice.
For example, if the arrays {1.1, 3.3, 4.4, 6.6, 1.1, 5.5, 3.3, 6.6} and (5.5, 9.9, 6.6, 8.8,
7.7. 9.9, 5.5) are passed to this method, it must return 2 since the numbers 6.6 and 5.5
are common between the two arrays.
3. A method named overlap that takes two arrays of double values and returns a new array
that contains the concatenation of them overlapped. Note that the two arrays may not be
of the same size.
For example, if the arrays (1.1, 3.3, 2.2} and {9.9, 4.4, 5.5, 6.6}are passed to the method,
it must return the array {1.1, 9.9, 3.3, 4.4, 2.2, 5.5, 6.6).
4. A method named greatestRow that takes a 2-dimensional array and returns a l-
dimensional array which represents the row with the greatest sum in the 2-dimesional
array
For example, if the following 2-D array is passed:
3.3 2.2 1.1
4.4 2.2 1.1
5.5 6.6 9.9 1.1
1.1 1.1 1.1 1.1 1.1
The method must return a reference to the array 5.5 6.6 9.9 1.1.
• Study the following two implementations of the copy method which takes a two-
dimensional array and returns a copy of it in two different ways, and understand the
difference between the two implementations.
First implementation: rows of new array are the same as rows of the source array.
public static double [] copy2D(double [[] source){
double (] dst = new double[source.length][]:
for(int i=0; i<source.length; i++)
dst[i] = sourceți):
return dst;
Second implementation: rows of new array are copies of rows of the source array.
public static double (] copy2D(double [D) source){
double (II] dst = new double/source.length]|]:
for(int i=0; i<source.length; i++){
dst[i] = new double[sourceli).length]:
for(int j=0: j<sourceli).length: j++)
dst[i]lj] = sourceli|lil:
return dst:
Whenever you need to construct a 2-dimensional array from other 1-dimensional arrays
or 2-dimensional arrays you can use one of these two approaches, depending on what
your application requires. A third extreme approach does not create a copy of the source
2-dimensional array, but assigns the address of the source array to the reference variable
of the destination array (dst = source).
5. A method named duplicateRow that takes a l-dimensional array of double values and an
integer. It retuns a 2-dimensional array that is formed by duplicating the passed 1-
dimensional array as rows as many times as defined in the passed integer.
For example, if the array (1.1, 2.2, 3.3, 4.4, 5.5} and the integer 3 are passed to this
method, it must return the 2-dimensional array:
1.1 2.2 3.3 4.4 5.5
1.1 2.2 3.3 4,4 5.5
1.1 2.2 3.3 4.4 5.5
6. A method named concatenate that takes two 2-dimensional arrays of double values and
retums a new 2-dimensional array that results from concatenating the two arrays by
combining their rows.
For example, if the first array is:
1.1 3.3 5.5 7.7
1.1 2.2
Transcribed Image Text:Write the following methods in vour class: 1. A method named duplicatesCount that takes an array of double values and returns the count of numbers duplicated (i.e. numbers that appear more than once) in the array, regardless of how many times each is duplicated. For example, if the array {1.1, 9.9, 4.4, 3.3, 3.3, 9.9, 2.2, 6.6, 7.7, 1.1, 9.9} is passed to this method, it must return 3 since the numbers 1.1, 9.9, and 3.3 appear more than once in the array. 2. A method named commonCount that takes two arrays of double values and returns the count of numbers that are common between the two arrays. If an element appears more than once it must not be counted twice. For example, if the arrays {1.1, 3.3, 4.4, 6.6, 1.1, 5.5, 3.3, 6.6} and (5.5, 9.9, 6.6, 8.8, 7.7. 9.9, 5.5) are passed to this method, it must return 2 since the numbers 6.6 and 5.5 are common between the two arrays. 3. A method named overlap that takes two arrays of double values and returns a new array that contains the concatenation of them overlapped. Note that the two arrays may not be of the same size. For example, if the arrays (1.1, 3.3, 2.2} and {9.9, 4.4, 5.5, 6.6}are passed to the method, it must return the array {1.1, 9.9, 3.3, 4.4, 2.2, 5.5, 6.6). 4. A method named greatestRow that takes a 2-dimensional array and returns a l- dimensional array which represents the row with the greatest sum in the 2-dimesional array For example, if the following 2-D array is passed: 3.3 2.2 1.1 4.4 2.2 1.1 5.5 6.6 9.9 1.1 1.1 1.1 1.1 1.1 1.1 The method must return a reference to the array 5.5 6.6 9.9 1.1. • Study the following two implementations of the copy method which takes a two- dimensional array and returns a copy of it in two different ways, and understand the difference between the two implementations. First implementation: rows of new array are the same as rows of the source array. public static double [] copy2D(double [[] source){ double (] dst = new double[source.length][]: for(int i=0; i<source.length; i++) dst[i] = sourceți): return dst; Second implementation: rows of new array are copies of rows of the source array. public static double (] copy2D(double [D) source){ double (II] dst = new double/source.length]|]: for(int i=0; i<source.length; i++){ dst[i] = new double[sourceli).length]: for(int j=0: j<sourceli).length: j++) dst[i]lj] = sourceli|lil: return dst: Whenever you need to construct a 2-dimensional array from other 1-dimensional arrays or 2-dimensional arrays you can use one of these two approaches, depending on what your application requires. A third extreme approach does not create a copy of the source 2-dimensional array, but assigns the address of the source array to the reference variable of the destination array (dst = source). 5. A method named duplicateRow that takes a l-dimensional array of double values and an integer. It retuns a 2-dimensional array that is formed by duplicating the passed 1- dimensional array as rows as many times as defined in the passed integer. For example, if the array (1.1, 2.2, 3.3, 4.4, 5.5} and the integer 3 are passed to this method, it must return the 2-dimensional array: 1.1 2.2 3.3 4.4 5.5 1.1 2.2 3.3 4,4 5.5 1.1 2.2 3.3 4.4 5.5 6. A method named concatenate that takes two 2-dimensional arrays of double values and retums a new 2-dimensional array that results from concatenating the two arrays by combining their rows. For example, if the first array is: 1.1 3.3 5.5 7.7 1.1 2.2
1.1 2.2
7.7 8.8 2.2
9.9 7.7 4.4
8.8 6.6
7. A method named addRow that takes two parameters: the first is a two-dimensional array
of doubles, and the second is a one-dimensional array of doubles. The method must
return a new two-dimensional array of doubles that results from adding the second
parameter (one-dimensional array) as a last row to the first parameter (two-dimensional
array).
The following implementation forms the new array by making it point to the same rows
of the 2-dimensional array and the 1-dimensional array:
public static double[]] addRow(double (][]array, double[]row){
double[]] newArray = new doublefarray.length+1]|):
for(int i=0; i<array.length; i++)
newArray[i]=arrsaylil:
newArray{newArray.length-1]=row;
return newArray:
In this assignment, you must implement this method in another way. Your
implementation must not work by copying references. Instead,
for each row and copy the individual elements.
must create new array
8. In your main method:
Note: you must print the affected array after each step. Consider defining methods
that print 1-D and 2-D arrays.
a. Define the following arrays:
listIDI with the following values: 4.4 5.5 2.2 1.1 5.5 2.2 2.2 9.9 7.7
listID2 with the following values: 7.7 6.6 3.3 2.2 2.2 7.7
b. Invoke the method duplicatesCount to print the count of numbers that appear more than
once in each of listID1 and list/D2.
c. Invoke the method commonCount to print the count of common numbers between the
arrays listlDI and listID2.
d. Define a new array listlD3 that results from overlapping the two arrays by invoking the
overlap method.
e. Define a two dimensional array named list2D that results from duplicating listID/ two
times as rows by invoking the duplicateRow method.
f. Add the arrays listID2 and listID3 as rows to the array list2D.
g. Print the row with the maximum sum in the array list2D by invoking the greatestRow.
h. Modify the array list2D such that it contains itself duplicated by invoking the
concatenate method.
3/3
:::
Transcribed Image Text:1.1 2.2 7.7 8.8 2.2 9.9 7.7 4.4 8.8 6.6 7. A method named addRow that takes two parameters: the first is a two-dimensional array of doubles, and the second is a one-dimensional array of doubles. The method must return a new two-dimensional array of doubles that results from adding the second parameter (one-dimensional array) as a last row to the first parameter (two-dimensional array). The following implementation forms the new array by making it point to the same rows of the 2-dimensional array and the 1-dimensional array: public static double[]] addRow(double (][]array, double[]row){ double[]] newArray = new doublefarray.length+1]|): for(int i=0; i<array.length; i++) newArray[i]=arrsaylil: newArray{newArray.length-1]=row; return newArray: In this assignment, you must implement this method in another way. Your implementation must not work by copying references. Instead, for each row and copy the individual elements. must create new array 8. In your main method: Note: you must print the affected array after each step. Consider defining methods that print 1-D and 2-D arrays. a. Define the following arrays: listIDI with the following values: 4.4 5.5 2.2 1.1 5.5 2.2 2.2 9.9 7.7 listID2 with the following values: 7.7 6.6 3.3 2.2 2.2 7.7 b. Invoke the method duplicatesCount to print the count of numbers that appear more than once in each of listID1 and list/D2. c. Invoke the method commonCount to print the count of common numbers between the arrays listlDI and listID2. d. Define a new array listlD3 that results from overlapping the two arrays by invoking the overlap method. e. Define a two dimensional array named list2D that results from duplicating listID/ two times as rows by invoking the duplicateRow method. f. Add the arrays listID2 and listID3 as rows to the array list2D. g. Print the row with the maximum sum in the array list2D by invoking the greatestRow. h. Modify the array list2D such that it contains itself duplicated by invoking the concatenate method. 3/3 :::
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY