Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Purpose: Demonstrate the ability to create and use Java arrays. Assignment: Firs

ID: 3634504 • Letter: P

Question

Purpose: Demonstrate the ability to create and use Java arrays.

Assignment: First, you should use Notepad (or any other text editor) to create a file ahead of time. The file should have 6 double values on separate lines. These values represent the earnings of a person for each of the first 6 months in a year; thus each double value will have exactly two places to the right of the decimal. Name this file, "earnings.txt", and save it to your desktop.

Your program should open and then read the 6 double values from this file into an array named 'earnings'. Use a 'for' loop to do this. Then use another 'for' loop to display the earnings as they were in the file.

After this, sort the array using Java's Arrays.sort() method, and then display the earnings in sorted order.
Finally, compute and display the average of the earnings.

For example, suppose that you created the file, "earnings.txt" and that the contents of the file are:

1012.30
1400.71
1250.78
5000.40
3050.70
2134.88

After your program executes its output would be:

The earnings from the file are:

1012.30
1400.71
1250.78
5000.40
3050.70
2134.88

After sorting the earnings are:

1012.30
1250.78
1400.71
2134.88
3050.70
5000.40

The average earnings for the half year is $2308.29

Explanation / Answer

/*you may also download the code from......http://www.2shared.com/file/BVKCDL-w/earn.html*/ #include #include using namespace std; void sortData(double data[]) { int i,j; double temp; for(i=0;i< 6;i++) { for(j=i+1;j< 6;j++) { if(data[i]>data[j]) { temp=data[i]; data[i]=data[j]; data[j]=temp; } } } } void print(double data[]) { int i; for(i=0;i< 6;i++) { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote