oldi and old2 arrays, as follows. Each element of sumarr will be equal to the sum of the correspondir elements of gldi and gld2. For example, sumarri0] will be oldi[0]+old2[0], sumarr[1] will be oldi[1]- old2[1] and so on. (You are using parallel arrays.) te a complete Java program to do the following: the main program will call a series of methods to ocess a set of data. One method will read data into two arrays. A second method will print the values red in an array. A third method will find the smallest of the values stored in an array. A fourth method I construct a new array from two existing arrays. A fifth method will compare the values in the two ays. Use files for both input and output. Be sure to pass the file variable to any method that will need E. The method whatsHigher will receive three parameters: two arrays (called scorel and score2), and integer n(giving the size of the two arrays). The method will compare the two arrays, element by eler to calculate in which array the value is higher. For each array element, the method will print which an the higher value (or if the two values are equal). The method should print each of the values, the arra from and the relationship. For example, for the data above, the method should print something like t following messages: The main program will read in a from the input file and call a method readData to read n items into two ays (which the main program will call scorel and score2). All data values must be read from a file, and all ues except the parameter value must be read in the method. Assume there are maximum 50 pairs of ues to read. In position O the higher value is in array score1: 18 is higher than 13 in position 1 the higher value is in array score2: 42 is higher than 21 in position 2 the value is the same in both arrays: 66 The main program will call a method printArray twice to print the values stored in the two arrays. (Call e method once to print array scorel and once to print array score2) Each time before the main program Is the printing method, it should print a heading saying what is being printed (for example, it could say orel array"). All output, including headings should go to a file. in addition, the method counts how many times the value from scorel is larger, how many times the from score2 is larger, and how many time the values in the two arrays are equal. Use local variables fo counters. Print these values before returning to the main method. For each array, the main program willi call a method smallest which will find the smallest of the n values red in an array. The main program will call the method once to find the smallest of the n values stored in escorel array, and once to find the smallest of the n values stored in the score2 array. After each call, the in program will print the returned value, together with a relevant message. DATA: Please read the data from a file which is to be prepared in advance (be sure to submit the file). parameter value of 10-15, but write a program which will work for any size arrays up to 50 or so. Mak that the smallest element does not occur in the first or the last position of an array. Make sure that th smallest element does not occur at the same position in each array. Make sure that the two arrays ha same value in at least one position. Try to make sure that the value make the counters printed at the have 3 different values. The main program will call a method construct. The method will construct a new array (which the main ogram will call sumscore) from the two arrays scorel and score2 Then construct will call printarray to nt the sumscore array. Either main or the method construct can print the heading for the sumscore ay. The sumscore array will need to be sent back to the main program, either as a return value or as an ay parameter. SAMPLE INPUT AND OUTPUT: (make yours larger) Input: The main program will call the method smallest again to find the smallest of then values stored in the mscore array. The main program will print this value. 6 95 94 98 98 The main program will call a method whatsHigher. This method will be used to compare the contents of scorel and score2 arrays. The method will receive three parameters: two arrays (scorel and score2), d an integer a (giving the size of the two arrays). The method will compare the two arrays, element by ment, to calculate in which array the corresponding value is higher. It will also count how many times e value in scorel is higher, and how many times in score2 is higher. It will print the counters, together ch clear messages 42 45 43 18 64 54 83 79 Sample output for this data file fyour order and words might be slightly different): re are the details of the methods. There are 6 values in each array The scorel array: 95 98 42 43 64 83 The method readData will read the data into two arrays. The method will receive three parameters: an eger n and two arrays which it calls numsi and nums2 At the beginning, only the parameter n will have alue. The value of a will be used to control the action of the method, as described below. The method will read n sets of data. Each set of data should contain two integers; the first will be read o nums1, and second will be read into nums2. (The values stored in these parameters will remain when e method returns to the main program, and they can be used throughout the program.) For example, opose the data set is the following The score2 array: 94 98 45 18 54 79 The smallest value in scorel is 42 The smallest value in score2 is 18 The sumscore array: 189 196 87 61 118 162

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
D. The method construct will receive four parameters: an integer k and three arrays called old1, old2, and
sumarr. The method will construct the first k elements of the sumarr array fromt the first k elements of the
oldi and old2 arrays, as follows. Each element of sumarr will be equal to the sum of the corresponding
elements of gldi and gld2. For example, sumarri0] will be old1[0]+old2[0], sumarr[1] will be old1[1] +
old2[1] and so on. (You are using parallel arrays.)
Write a complete Java program to do the following: the main program will call a series of methods to
process a set of data. One method will read data into two arrays. A second method will print the values
stored in an array. A third method will find the smallest of the values stored in an array. A fourth method
will construct a new array from two existing arrays. A fifth method will compare the values in the two
arrays. Use files for both input and output. Be sure to pass the file variable to any method that will need
it.
E. The method whatsHigher will receive three parameters: two arrays (called scorel and score2), and an
integer n(giving the size of the two arrays). The method will compare the two arrays, element by element,
to calculate in which array the value is higher. For each array element, the method will print which array has
the higher value (or if the two values are equal). The method should print each of the values, the array it is
from and the relationship. For example, for the data above, the method should print something like the
following messages:
1. The main program will read in n from the input file and call a method readData to read n items into two
arrays (which the main program will call scorel and score2). All data values must be read from a file, and all
values except the parameter value must be read in the method. Assume there are maximum 50 pairs of
values to read.
In position 0 the higher value is in array score1: 18 is higher than 13
in position 1 the higher value is in array score2: 42 is higher than 21
in position 2 the value is the same in both arrays: 66
2. The main program will call a method printArray twice to print the values stored in the two arrays. (Call
the method once to print array scorel and once to print array score2.) Each time before the main program
calls the printing method, it should print a heading saying what is being printed (for example, it could say
"scorel array"). All output, including headings should go to a file.
In addition, the method counts how many times the value from scorel is larger, how many times the value
from score2 is larger, and how many time the values in the two arrays are equal. Use local variables for the
counters. Print these values before returning to the main method.
3. For each array, the main program will call a method smallest which will find the smallest of the n values
stored in an array. The main program will call the method once to find the smallest of the n values stored in
the scorel array, and once to find the smallest of the n values stored in the score2 array. After each call, the
DATA: Please read the data from a file which is to be prepared in advance (be sure to submit the file). Use a
parameter value of 10-15, but write a program which will work for any size arrays up to 50 or so. Make sure
that the smallest element does not occur in the first or the last position of an array. Make sure that the
smallest element does not occur at the same position in each array. Make sure that the two arrays have the
same value in at least one position. Try to make sure that the value make the counters printed at the end
have 3 different values.
main program will print the returned value, together with a relevant message.
4. The main program will call a method construct. The method will construct a new array (which the main
program will call sumscore) from the two arrays scorel and score2. Then construct will call printarray to
print the sumscore array. Either main or the method construct can print the heading for the sumscore
array. The sumscore array will need to be sent back to the main program, either as a return value or as an
array parameter.
SAMPLE INPUT AND OUTPUT: (make yours larger)
Input:
5. The main program will call the method smallest again to find the smallest of the n values stored in the
sumscore array. The main program will print this value.
6
95 94
98
98
6. The main program will call a method whatsHigher. This method will be used to compare the contents of
the scorel and score2 arrays. The method will receive three parameters: two arrays (scorel and score2),
and an integer n (giving the size of the two arrays). The method will compare the two arrays, element by
element, to calculate in which array the corresponding value is higher. It will also count howw many times
the value in scorel is higher, and how many times in scere2 is higher. It will print the counters, together
with clear messages.
42
45
43
18
64
54
83
79
Sample output for this data file (your order and words might be slightly different):
Here are the details of the methods.
There are 6 values in each array.
The scorel array:
95 98 42 43 64 83
The score2 array:
A. The method readData will read the data into two arrays. The method will receive three parameters: an
integer n, and two arrays which it calls nums1 and nums2. At the beginning, only the parameter n will have
a value. The value of a will be used to control the action of the method, as described below.
The method will read n sets of data. Each set of data should contain two integers; the first will be read
into nums1, and second will be read into nums2. (The values stored in these parameters will remain when
the method returns to the main program, and they can be used throughout the program.) For example,
suppose the data set is the following:
94 98 45 18 54 79
The smallest value in scorel is 42
The smallest value in score2 is 18
The sumscore array: 189 196 87 61 118 162
3
18
13
The smallest value in sumscore is 61
21
42
In position 0, array scorel is larger: 95 is greater than 94
In position 1, the two arrays have the same value: 98
66
66
The main program will read the value 3 into the variable n. In readData, the array numsl will get the values
18, 21, and 66, and the array nums2 will get the values 13, 42, 66. Note that you cannot read down the
column of values - the two values you read will come from the same line, and you will place the values into
the two arrays.
Array scorel was larger 4 time(s)
Array score2 was larger 1 time(s)
The two arrays were equal 1 time(s)
B The method printArray will receive two parameters, an integer lim, and an array called vals. It will print
the lim values stored in the array vals, all on one line, with spaces between the values.
C. The method smallest will receive two parameters, an integer num and an array called arr. It will find and
return the smallest of the first num elements of the arr array.
Transcribed Image Text:D. The method construct will receive four parameters: an integer k and three arrays called old1, old2, and sumarr. The method will construct the first k elements of the sumarr array fromt the first k elements of the oldi and old2 arrays, as follows. Each element of sumarr will be equal to the sum of the corresponding elements of gldi and gld2. For example, sumarri0] will be old1[0]+old2[0], sumarr[1] will be old1[1] + old2[1] and so on. (You are using parallel arrays.) Write a complete Java program to do the following: the main program will call a series of methods to process a set of data. One method will read data into two arrays. A second method will print the values stored in an array. A third method will find the smallest of the values stored in an array. A fourth method will construct a new array from two existing arrays. A fifth method will compare the values in the two arrays. Use files for both input and output. Be sure to pass the file variable to any method that will need it. E. The method whatsHigher will receive three parameters: two arrays (called scorel and score2), and an integer n(giving the size of the two arrays). The method will compare the two arrays, element by element, to calculate in which array the value is higher. For each array element, the method will print which array has the higher value (or if the two values are equal). The method should print each of the values, the array it is from and the relationship. For example, for the data above, the method should print something like the following messages: 1. The main program will read in n from the input file and call a method readData to read n items into two arrays (which the main program will call scorel and score2). All data values must be read from a file, and all values except the parameter value must be read in the method. Assume there are maximum 50 pairs of values to read. In position 0 the higher value is in array score1: 18 is higher than 13 in position 1 the higher value is in array score2: 42 is higher than 21 in position 2 the value is the same in both arrays: 66 2. The main program will call a method printArray twice to print the values stored in the two arrays. (Call the method once to print array scorel and once to print array score2.) Each time before the main program calls the printing method, it should print a heading saying what is being printed (for example, it could say "scorel array"). All output, including headings should go to a file. In addition, the method counts how many times the value from scorel is larger, how many times the value from score2 is larger, and how many time the values in the two arrays are equal. Use local variables for the counters. Print these values before returning to the main method. 3. For each array, the main program will call a method smallest which will find the smallest of the n values stored in an array. The main program will call the method once to find the smallest of the n values stored in the scorel array, and once to find the smallest of the n values stored in the score2 array. After each call, the DATA: Please read the data from a file which is to be prepared in advance (be sure to submit the file). Use a parameter value of 10-15, but write a program which will work for any size arrays up to 50 or so. Make sure that the smallest element does not occur in the first or the last position of an array. Make sure that the smallest element does not occur at the same position in each array. Make sure that the two arrays have the same value in at least one position. Try to make sure that the value make the counters printed at the end have 3 different values. main program will print the returned value, together with a relevant message. 4. The main program will call a method construct. The method will construct a new array (which the main program will call sumscore) from the two arrays scorel and score2. Then construct will call printarray to print the sumscore array. Either main or the method construct can print the heading for the sumscore array. The sumscore array will need to be sent back to the main program, either as a return value or as an array parameter. SAMPLE INPUT AND OUTPUT: (make yours larger) Input: 5. The main program will call the method smallest again to find the smallest of the n values stored in the sumscore array. The main program will print this value. 6 95 94 98 98 6. The main program will call a method whatsHigher. This method will be used to compare the contents of the scorel and score2 arrays. The method will receive three parameters: two arrays (scorel and score2), and an integer n (giving the size of the two arrays). The method will compare the two arrays, element by element, to calculate in which array the corresponding value is higher. It will also count howw many times the value in scorel is higher, and how many times in scere2 is higher. It will print the counters, together with clear messages. 42 45 43 18 64 54 83 79 Sample output for this data file (your order and words might be slightly different): Here are the details of the methods. There are 6 values in each array. The scorel array: 95 98 42 43 64 83 The score2 array: A. The method readData will read the data into two arrays. The method will receive three parameters: an integer n, and two arrays which it calls nums1 and nums2. At the beginning, only the parameter n will have a value. The value of a will be used to control the action of the method, as described below. The method will read n sets of data. Each set of data should contain two integers; the first will be read into nums1, and second will be read into nums2. (The values stored in these parameters will remain when the method returns to the main program, and they can be used throughout the program.) For example, suppose the data set is the following: 94 98 45 18 54 79 The smallest value in scorel is 42 The smallest value in score2 is 18 The sumscore array: 189 196 87 61 118 162 3 18 13 The smallest value in sumscore is 61 21 42 In position 0, array scorel is larger: 95 is greater than 94 In position 1, the two arrays have the same value: 98 66 66 The main program will read the value 3 into the variable n. In readData, the array numsl will get the values 18, 21, and 66, and the array nums2 will get the values 13, 42, 66. Note that you cannot read down the column of values - the two values you read will come from the same line, and you will place the values into the two arrays. Array scorel was larger 4 time(s) Array score2 was larger 1 time(s) The two arrays were equal 1 time(s) B The method printArray will receive two parameters, an integer lim, and an array called vals. It will print the lim values stored in the array vals, all on one line, with spaces between the values. C. The method smallest will receive two parameters, an integer num and an array called arr. It will find and return the smallest of the first num elements of the arr array.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

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