Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

When I try to combine the data collected through my two methods and print through main the data ends up null or all zeros.

**(1)**How do I get the data collected from the methods to print through main so it can be as such

Name -- Score

**(2)**Also, how can I clear up the System.out prints of sums to have it looped to each Sum Array (Sum 1 through Sum9).

Name -- Score

```
import java.io.*;
import java.util.*;
import java.lang.*;
public class Assignment10
{
public static double lowestScore = Double.MAX_VALUE;
public static double highestScore = Double.MIN_VALUE;
static String[] names = new String[9];
public static void getName() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("data.txt"));
for(int i = 0; i < names.length; i++)
{
names[i] = inFile.next() + " " + inFile.next();
inFile.nextLine();
}
System.out.print(Arrays.toString(names));
}
public static void getScore() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("diving_data.txt"));
double[] scores = new double[72];
Double total = 0.00;
Double Sum1, Sum2, Sum3, Sum4, Sum5, Sum6, Sum7, Sum8, Sum9;
int index = 0;
while(inFile.hasNext()) {
if(inFile.hasNextDouble()) {
scores[index++] = inFile.nextDouble();
}
else {
inFile.next();
}
}
Sum1 = scores[0] + scores[1] + scores[4] + scores[5] + scores[6] + scores[7];
Sum2 = scores[8] + scores[9] + scores[11] + scores[12] + scores[13] + scores[14];
Sum3 = scores[16] + scores[17] + scores[20] + scores[21] + scores[22] + scores[23];
Sum4 = scores[24] + scores[25] + scores[26] + scores[28] + scores[29] + scores[30];
Sum5 = scores[32] + scores[33] + scores[35] + scores[36] + scores[37] + scores[38];
Sum6 = scores[40] + scores[41] + scores[42] + scores[43] + scores[45] + scores[46];
Sum7 = scores[48] + scores[49] + scores[52] + scores[53] + scores[54] + scores[55];
Sum8 = scores[56] + scores[58] + scores[59] + scores[60] + scores[61] + scores[62];
Sum9 = scores[66] + scores[67] + scores[68] + scores[69] + scores[70] + scores[71];
System.out.println(Sum1); // test
}
public static void main(String[] args) throws FileNotFoundException
{
getScore();
getName();
}
}
```

Do more with

EXPERT OFFICE^{®} is a registered trademark of EXPERTS EXCHANGE^{®}

you need to print each one individually:

System.out.println(Sum1);

System.out.println(Sum2);

System.out.println(Sum3);

etc.

Please, post data.txt and driviong_data.txt, so that

I could test it in reality and see why you get zeroes.

All the numbers which you manipuilate with (in particular

doing arithmetic operations) should be prinmirtive double

Class Double is used for special opertaions - like converting strings to

double, etc.

I modified the last part of your code - made indeed array sum

and printed it as array.

Still to fix and test the program we'd like to have the input files

```
import java.io.*;
import java.util.*;
import java.lang.*;
public class Assignment10
{
public static double lowestScore = Double.MAX_VALUE;
public static double highestScore = Double.MIN_VALUE;
static String[] names = new String[9];
public static void getName() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("data.txt"));
for(int i = 0; i < names.length; i++)
{
names[i] = inFile.next() + " " + inFile.next();
inFile.nextLine();
}
System.out.print(Arrays.toString(names));
}
public static void getScore() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("diving_data.txt"));
double[] scores = new double[72];
//Double total = 0.00;
// Double Sum1, Sum2, Sum3, Sum4, Sum5, Sum6, Sum7, Sum8, Sum9;
double total = 0.0;
double [] sum = new double[9];
int index = 0;
while(inFile.hasNext()) {
if(inFile.hasNextDouble()) {
scores[index++] = inFile.nextDouble();
}
else {
inFile.next();
}
}
/*
Sum1 = scores[0] + scores[1] + scores[4] + scores[5] + scores[6] + scores[7];
Sum2 = scores[8] + scores[9] + scores[11] + scores[12] + scores[13] + scores[14];
Sum3 = scores[16] + scores[17] + scores[20] + scores[21] + scores[22] + scores[23];
Sum4 = scores[24] + scores[25] + scores[26] + scores[28] + scores[29] + scores[30];
Sum5 = scores[32] + scores[33] + scores[35] + scores[36] + scores[37] + scores[38];
Sum6 = scores[40] + scores[41] + scores[42] + scores[43] + scores[45] + scores[46];
Sum7 = scores[48] + scores[49] + scores[52] + scores[53] + scores[54] + scores[55];
Sum8 = scores[56] + scores[58] + scores[59] + scores[60] + scores[61] + scores[62];
Sum9 = scores[66] + scores[67] + scores[68] + scores[69] + scores[70] + scores[71];
System.out.println(Sum1); // test
*/
sum[0] = scores[0] + scores[1] + scores[4] + scores[5] + scores[6] + scores[7];
sum[1] = scores[8] + scores[9] + scores[11] + scores[12] + scores[13] + scores[14];
sum[2] = scores[16] + scores[17] + scores[20] + scores[21] + scores[22] + scores[23];
sum[3] = scores[24] + scores[25] + scores[26] + scores[28] + scores[29] + scores[30];
sum[4] = scores[32] + scores[33] + scores[35] + scores[36] + scores[37] + scores[38];
sum[5] = scores[40] + scores[41] + scores[42] + scores[43] + scores[45] + scores[46];
sum[6] = scores[48] + scores[49] + scores[52] + scores[53] + scores[54] + scores[55];
sum[7] = scores[56] + scores[58] + scores[59] + scores[60] + scores[61] + scores[62];
sum[8] = scores[66] + scores[67] + scores[68] + scores[69] + scores[70] + scores[71];
for(int j=0; j<9; j++){
System.out.println("Sum [" + j + "]=" + sum[j]);
}
//System.out.println(Sum1); // test
}
public static void main(String[] args) throws FileNotFoundException
{
getScore();
getName();
}
}
```

I modified your program, commented out some of your pieces,

and replaced it with different code, also invented some input files.

Look at it and let me know if you have any questions.

```
import java.io.*;
import java.util.*;
import java.lang.*;
public class Assignment10
{
public static double lowestScore = Double.MAX_VALUE;
public static double highestScore = Double.MIN_VALUE;
static String[] names = new String[9];
public static void getName() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("data.txt"));
for(int i = 0; i < names.length; i++)
{
names[i] = inFile.next() + " " + inFile.next();
//inFile.nextLine();
}
System.out.print(Arrays.toString(names));
}
public static void getScore() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("diving_data.txt"));
double[] scores = new double[72];
//Double total = 0.00;
// Double Sum1, Sum2, Sum3, Sum4, Sum5, Sum6, Sum7, Sum8, Sum9;
double total = 0.0;
double [] sum = new double[9];
int index = 0;
//while(inFile.hasNext()) {
while(inFile.hasNextDouble()) {
if(index > 71)break;
scores[index++] = inFile.nextDouble();
}
// else {
// inFile.next();
// }
//}
/*
Sum1 = scores[0] + scores[1] + scores[4] + scores[5] + scores[6] + scores[7];
Sum2 = scores[8] + scores[9] + scores[11] + scores[12] + scores[13] + scores[14];
Sum3 = scores[16] + scores[17] + scores[20] + scores[21] + scores[22] + scores[23];
Sum4 = scores[24] + scores[25] + scores[26] + scores[28] + scores[29] + scores[30];
Sum5 = scores[32] + scores[33] + scores[35] + scores[36] + scores[37] + scores[38];
Sum6 = scores[40] + scores[41] + scores[42] + scores[43] + scores[45] + scores[46];
Sum7 = scores[48] + scores[49] + scores[52] + scores[53] + scores[54] + scores[55];
Sum8 = scores[56] + scores[58] + scores[59] + scores[60] + scores[61] + scores[62];
Sum9 = scores[66] + scores[67] + scores[68] + scores[69] + scores[70] + scores[71];
System.out.println(Sum1); // test
*/
sum[0] = scores[0] + scores[1] + scores[4] + scores[5] + scores[6] + scores[7];
sum[1] = scores[8] + scores[9] + scores[11] + scores[12] + scores[13] + scores[14];
sum[2] = scores[16] + scores[17] + scores[20] + scores[21] + scores[22] + scores[23];
sum[3] = scores[24] + scores[25] + scores[26] + scores[28] + scores[29] + scores[30];
sum[4] = scores[32] + scores[33] + scores[35] + scores[36] + scores[37] + scores[38];
sum[5] = scores[40] + scores[41] + scores[42] + scores[43] + scores[45] + scores[46];
sum[6] = scores[48] + scores[49] + scores[52] + scores[53] + scores[54] + scores[55];
sum[7] = scores[56] + scores[58] + scores[59] + scores[60] + scores[61] + scores[62];
sum[8] = scores[66] + scores[67] + scores[68] + scores[69] + scores[70] + scores[71];
for(int j=0; j<9; j++){
System.out.println("Sum [" + j + "]=" + sum[j]);
}
//System.out.println(Sum1); // test
}
public static void main(String[] args) throws FileNotFoundException
{
getScore();
getName();
}
}
```

diving_data.txt:

```
1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19 20 21
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74
```

data.txt:

```
item_1 item_2
item_3 item_4
item_5 item_6
item_7 item_8
item_9 item_10
item_11 item_12
item_13 item_14
item_15 item_16
item_17 item_18
item_19 item_20
```

Output of the above program:

```
Sum [0]=29.0
Sum [1]=73.0
Sum [2]=125.0
Sum [3]=168.0
Sum [4]=217.0
Sum [5]=263.0
Sum [6]=317.0
Sum [7]=362.0
Sum [8]=417.0
[item_1 item_2, item_3 item_4, item_5 item_6, item_7 item_8, item_9 item_10, item_11 item_12, item_13 item_14, item_15 item_16, item_17 item_18]
```

You don't need the score() method to run this

progra, I modified it so that it reads everything and calcultes in the first

method getName()

Try to run it.

```
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;
import java.lang.*;
public class Assignment10
{
public static double lowestScore = Double.MAX_VALUE;
public static double highestScore = Double.MIN_VALUE;
static String[] names = new String[9];
public static void getName() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("diving-data.txt"));
for(int i = 0; i < names.length; i++)
{
String buff = inFile.nextLine();
if(buff.trim().length() == 0)continue;
StringTokenizer t = new StringTokenizer(buff);
names[i] = t.nextToken() + " " + t.nextToken();
double sum = 0.0;
while(t.hasMoreTokens()){
sum += Double.parseDouble(t.nextToken());
}
DecimalFormat formatter = new DecimalFormat("###.#");
System.out.println(names[i] + " Sum: " + formatter.format(sum));
//names[i] = inFile.next() + " " + inFile.next();
//inFile.nextLine();
}
//System.out.print(Arrays.toString(names));
}
public static void getScore() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("diving_data.txt"));
double[] scores = new double[72];
//Double total = 0.00;
// Double Sum1, Sum2, Sum3, Sum4, Sum5, Sum6, Sum7, Sum8, Sum9;
double total = 0.0;
double [] sum = new double[9];
int index = 0;
//while(inFile.hasNext()) {
while(inFile.hasNextDouble()) {
if(index > 71)break;
scores[index++] = inFile.nextDouble();
}
// else {
// inFile.next();
// }
//}
/*
Sum1 = scores[0] + scores[1] + scores[4] + scores[5] + scores[6] + scores[7];
Sum2 = scores[8] + scores[9] + scores[11] + scores[12] + scores[13] + scores[14];
Sum3 = scores[16] + scores[17] + scores[20] + scores[21] + scores[22] + scores[23];
Sum4 = scores[24] + scores[25] + scores[26] + scores[28] + scores[29] + scores[30];
Sum5 = scores[32] + scores[33] + scores[35] + scores[36] + scores[37] + scores[38];
Sum6 = scores[40] + scores[41] + scores[42] + scores[43] + scores[45] + scores[46];
Sum7 = scores[48] + scores[49] + scores[52] + scores[53] + scores[54] + scores[55];
Sum8 = scores[56] + scores[58] + scores[59] + scores[60] + scores[61] + scores[62];
Sum9 = scores[66] + scores[67] + scores[68] + scores[69] + scores[70] + scores[71];
System.out.println(Sum1); // test
*/
sum[0] = scores[0] + scores[1] + scores[4] + scores[5] + scores[6] + scores[7];
sum[1] = scores[8] + scores[9] + scores[11] + scores[12] + scores[13] + scores[14];
sum[2] = scores[16] + scores[17] + scores[20] + scores[21] + scores[22] + scores[23];
sum[3] = scores[24] + scores[25] + scores[26] + scores[28] + scores[29] + scores[30];
sum[4] = scores[32] + scores[33] + scores[35] + scores[36] + scores[37] + scores[38];
sum[5] = scores[40] + scores[41] + scores[42] + scores[43] + scores[45] + scores[46];
sum[6] = scores[48] + scores[49] + scores[52] + scores[53] + scores[54] + scores[55];
sum[7] = scores[56] + scores[58] + scores[59] + scores[60] + scores[61] + scores[62];
sum[8] = scores[66] + scores[67] + scores[68] + scores[69] + scores[70] + scores[71];
for(int j=0; j<9; j++){
System.out.println("Sum [" + j + "]=" + sum[j]);
}
//System.out.println(Sum1); // test
}
public static void main(String[] args) throws FileNotFoundException
{
//getScore();
getName();
}
}
```

```
Chen Ruolin 9.2 9.3 9 9.9 9.5 9.5 9.6 9.8
Emilie Heymans 9.2 9.2 9 9.9 9.5 9.5 9.7 9.6
Wang Xin 9.2 9.2 9.1 9.9 9.5 9.6 9.4 9.8
Paola Espinosa 9.2 9.3 9.2 9 9.5 9.3 9.6 9.8
Tatiana Ortiz 9.2 9.3 9 9.4 9.1 9.5 9.6 9.8
Melissa Wu 9.2 9.3 9.3 9.7 9.2 9.2 9.6 9.8
Marie-Eve Marleau 9.2 9.2 9.2 9.9 9.5 9.2 9.3 9.8
Tonia Couch 9.2 9 9.1 9.5 9.2 9.3 9.4 9.6
Laura Wilkinson 9.7 9.1 9.3 9.4 9.5 9.4 9.6 9.2
```

```
Chen Ruolin Sum: 75.8
Emilie Heymans Sum: 75.6
Wang Xin Sum: 75.7
Paola Espinosa Sum: 74.9
Tatiana Ortiz Sum: 74.9
Melissa Wu Sum: 75.3
Marie-Eve Marleau Sum: 75.3
Tonia Couch Sum: 74.3
Laura Wilkinson Sum: 75.2
```

## Premium Content

You need an Expert Office subscription to comment.Start Free Trial