Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Question 7. (30 pts) Write a complete Java program with comments in main and in each me Data: The input data for this program

Java
image text in transcribed
Question 7. (30 pts) Write a complete Java program with comments in main and in each me Data: The input data for this program is given as two columns of numbers All data will be entered from a file named input.txt and all output will go to the screen Assume there will not be more than 100 rows of data in the file 7 23.56 6 88.12 10 75. Design a Java class with a main method that does the following: 1) Reads the data into two arrays of doubles, arri and arr2, by invoking the method readData. with both arrays as parameters. The return value from readData should be stored in an integer variable num 2) Modifes all of he values in the arr2 array by inwoking the method changeArray, passing both arrays and num as parameters and ance for arr the numbers right aligned 3) Sort arrl and arr2 separately by invoking the method sortArray twice-once for arri 4) Prints the values in both arrays to the screen in two columns as shown below with a header and arri arr2 10.00 751.00 16.00 1409.92 The readData method reads two doubles values from the input file. The first value of each line is stored in arrOne, and the second value is stored in arrTwo. For example, in the Sample Data above, 7 would go into arrOne[0] and 23.56 would go into arrTwo[0]. This is repeated until there are no more values in the file. Parameters arrone- an array of doubles for storing the 1st value read in per rovw arrTwo -an array of doubles for storing the 2nd value read in per row Returns num- an integer representing the number of rows that were read in The changeArray method has parameters alpha-an array of doubles beta - an array of doubles k - an integer representing the number of elements in alpha and bet to be processed The method multiplies each element of beta by the corresponding value of alpha and stores the result into beta. For example, beta[0],7, is multiplied by alpha[0], 23,56 and the result 164.92, is stored in beta[0] The sortArray method sorts the first k elements of the parameter Parameters array into ascending order arrToOrder-an array of doubles to be sorted k - an integer representing the number of elements in the array arrToOrder

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

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions