Java Program

CISC 1115 Fall 2021 Assignment 3

 

Don't use plagiarized sources. Get Your Custom Essay on
Java Program
Just from $13/Page
Order Essay

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.

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 score1 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.

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 score1 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 “score1 array”). All output, including headings should go to a file.

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 score1 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.

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 score1 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.

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. The main program will call a method whatsHigher. This method will be used to compare the contents of the score1 and score2 arrays. The method will receive three parameters: two arrays (score1 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 score1 is higher, and how many times in score2 is higher. It will print the counters, together with clear messages.

Here are the details of the methods.

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:

3 18 13 21 42 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.

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.

D. The method construct will receive four parameters: an integer k, and three arrays called old1old2, and sumarr. The method will construct the first k elements of the sumarr array fromt the first k elements of the old1 and old2 arrays, as follows. Each element of sumarr will be equal to the sum of the corresponding elements of old1 and old2. For example, sumarr[0] will be old1[0]+old2[0], sumarr[1] will be old1[1] + old2[1] and so on. (You are using parallel arrays.)

E. The method whatsHigher will receive three parameters: two arrays (called score1 and score2), and an integer (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:

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

In addition, the method counts how many times the value from score1 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.

DATA: 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.

SAMPLE INPUT AND OUTPUT: (make yours larger)

Input:

6 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 score1 array: 95 98 42 43 64 83 The score2 array: 94 98 45 18 54 79

The smallest value in score1 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 score1 is larger: 95 is greater than 94 In position 1, the two arrays have the same value: 98 …

Array score1 was larger 4 time(s) Array score2 was larger 1 time(s) The two arrays were equal 1 time(s)

Essay Writing Pros
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

Our writers have been trained on how to handle papers placed by our clients. The writer must read and understand before embarking on writing the papers. In case of any issue that needs clarification, writers are encouraged to ask the client or support.

Professional and Experienced Academic Writers

Our team comprises of the best writers and editors. We do thorough vetting during recruitment to make sure that our writers have the knowledge and experience we aspire in the team.

Free Unlimited Revisions

Our aim is to give the client the best outcome. If for some reason you are not satisfied with the wok done, you can ask the paper to be revised or rewritten. This will be done to your satisfaction with no extra charges.

Prompt Delivery and 100% Money-Back-Guarantee

We have writers who work round the clock. This helps in making sure that all our clients’ papers are delivered on time. If we have issues with the deadline, we will ask for extension. If its not possible, the money is fully refunded.

Original & Confidential

Our clients’ confidentiality is highly respected. We can never disclose our clients’ details to third parties. In the same regard, we strive to give our clients 100% original papers. We do not tolerate plagiarism from our writers.

24/7 Customer Support

Clients can reach us any time of the day, and any day of the week. There is a live chat, email or phone numbers to help in ease of communication.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

You should never be worried about your papers even in the middle of the night. Our team will work round the clock to deliver.

Essays

Essay Writing Service

We have an able team that can deliver your work in the shortest time possible. The academic level or the type of work should never be a hindrance. Our highly competent support team is always around (24/7) to give you any assistance you may need.

Admissions

Admission Essays & Business Writing Help

Do you need to be admitted in your dream institution but find it challenging to write an admission essay? Our team is in a position to write the best letter that will guarantee you an admission. We do as well write the best business proposals and reports.

Reviews

Editing Support

Writing can be fun and enjoyable when everything has been done right. Writing is not just enough without proper editing and proofreading. We have a team of editors that ensure everything falls in place, whether its issues to do with grammar or referencing styles.

Reviews

Revision Support

Once the paper has been done and submitted, that is not the end of it. You can always ask for amendment or improvement if you feel something has not been done right. Our team of writers and editors will gladly assist you to your satisfaction. Revision is free of charge.