Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please write it in JAVA, but please follow all the instructions. I already posted one but didn't get the full asnwer. Homework -

Can you please write it in JAVA, but please follow all the instructions. I already posted one but didn't get the full asnwer.image text in transcribed

Homework - Topic 7 cont. - Count Zeros: Write a complete program to do the following: (a) Write a method called readData0 which receives two parameters, an array of integers called vals, which is initially uninitialized, and a reference to an output file. The method reads integers from an input file until it reaches EOF, storing the data values in the array vals. The method counts how many integers were read into the array. The method prints the data values read in and the count to an output file. The method returns the filled-in array and the total number of data values read in. (b) Write a method called countZeros 0 which receives two parameters, an integer n and an array of integers called vals. The method counts and returns how many of the first n elements of the vals array are 0 . For example, if the array holds 66040431 with n=6, it has two 0 values. (c) Write a method called append0 which reads in several new values (from a second input file) into an array of integers, appending them at the end of the array. The method array and the value of n. The method returns the updated array as well as the new total number of data values stored within the array. For example, Assume the array initially holds 660040431 with n=6; after the that several new 0 values are added to the array.) (d) Write a main program which calls these methods. First, the main program calls readData() to read a set of data into an array called numbers, which contains no more than 100 integers. The number of elements actually read is returned by the method and stored in a variable called size. Then, the main program calls the method countZeros() to find out how many of the size array elements are 0 . The main program prints this value to the output file. Next, the main program calls append() to modify the numbers array and the value of size. The append ( method reads in new values from a file until input failure (i.e., EOF is reached), appending the new values to the end of the existing array and incrementing the number of values stored within the array. The complete revised array and new total count are printed (in either the main program or the method) to the output file. Finally, the main program calls the method countZeros 0 again to determine how many elements in the new array are 0 and prints the result to the output file. Required Submission: 1. The Java source code file (e.g., HW7_2.java) 2. The initial input file (initNums.txt) 3. The secondary input file (e.g., moreNums.txt) 4. The program generated output file (e.g., output.txt)

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

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

Refer to Example 10.18 and find a 90% confidence interval for /0.

Answered: 1 week ago

Question

1. In what ways has flexible working revolutionised employment?

Answered: 1 week ago