In the following program I have coded a program that reads in 5 student names, along with marks for each for 5 quizes for each student. I have loades the names in an ArrayList of type String and the quiz marks in an ArrayList of type Double. However I need to load these quiz marks into a Integer and I am not sure how to change this
import java.util.Scanner;
import java.util.ArrayList;
public class onemoretime
{
public static final double MAX_SCORE = 15 ;
public static final int NAMELIMIT = 5;
public static void main(String[] args)
{
ArrayList<String> names = new ArrayList<>();
ArrayList<Double> averages = new ArrayList<>(); //line that needs to become a Integer ArrayList
Scanner in = new Scanner(System.in);
for (int i = 0; i < NAMELIMIT; i++)
{
String line = in.nextLine();
String[] words = line.split(" ");
String name = words[0] + " " + words[1];
double average = findAverage(words[2], words[3], words[4], words[5], words[6]);
System.out.println("Name: " + name + " Quiz Avg: " + average);
names.add(name);
averages.add(average);
}
}
public static double findAverage(String a, String b, String c, String d, String e)
{
double sum = Double.parseDouble(a) + Double.parseDouble(b) + Double.parseDouble(c) + Double.parseDouble(d) + Double.parseDouble(e);
return (sum / NAMELIMIT);
}
}
For the input:
Sally Mae 90 80 45 60 75
Charlotte Tea 60 75 80 90 70
Oliver Cats 55 65 76 90 80
Milo Peet 90 95 85 75 80
Gavin Brown 45 65 75 55 80
I am getting the correct output
Name: Sally Mae Quiz Avg: 70.0
Name: Charlotte Tea Quiz Avg: 75.0
Name: Oliver Cats Quiz Avg: 73.2
Name: Milo Peet Quiz Avg: 85.0
Name: Gavin Brown Quiz Avg: 64.0