Input: 95 94 98 98 42 45 43 18 64 54 83 79 Sample output for this data file (your order and words might be slightly different): There are 6 values in each array. The scorel array: 95 98 42 43 64 83 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 The smallest value in sumscore is 61 In position 0, array scorel is larger: 95 is greater than 94 In position 1, the two arrays have the same value: 98 Array scorel was larger 4 time(s) Array score2 was larger 1 time(s) The two arrays were equal 1 time(s)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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 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
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
main 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). 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.
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 how many times
the value in scorel is higher, and how many times in score2 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 n 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 nums1 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 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 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 main 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). 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. 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 how many times the value in scorel is higher, and how many times in score2 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 n 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 nums1 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 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education