Question: Making a Program to read a .txt file and average the scores for each student: This is the Problem i'm working on: Trying to read
Making a Program to read a .txt file and average the scores for each student:
This is the Problem i'm working on: Trying to read the .txt file into an array to the program below to finish it and inform the user of each students average score and number of quizes.
The .txt file within the src file of the program reads the following below:
Jeff 12.5 15 18 17 19.5 16.5 20 Brian 20.0 19.5 20 18.5 19.0 20 Jenny 13.5 20.0 19.5 20 18.5 19.0 20 18.5 Navid 18 17 19.5 16.5 19.5 20 18.5 19.0 Carl 12.5 15 15 15 19.5 16.5 20 Felix 20.0 17.5 18 18.5 19.0 20 Hannah 19.5 20.0 16.5 20 18.5 9.0 20 18.5 Eric 20 18.5 9.0 20 20
Add a method to the Student class called getNumQuizzes() to
* return the number of quizzes for this student.
*/
/*
* Create code in main() (new class) to perform these tasks:
*/
// Read a line from quizScores.txt
// Create student1 using the student name from the file
// Add quiz scores for each quiz score in the file.
/*
* Print these items with appropriate labels:
* Student name, number quizzes, average score
*/
/* *****************************************************
* Challenge Level: Max score of 100%
* ***************************************************** */
/*
* Add printing to QuizAverages.txt. Use the same format as your
* output to the console.
* Modify the code to loop until every line in quizScores.txt
* has been processed.
* Print an extra line at the end to say: "Quiz averages stored
* in file: "
This is the Program mentioned previously:
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Students {
private int numberQuizes;
private int totalScores;
private int QuizAverage;
public Students() {
numberQuizes = 0;
totalScores = 0;
}
public void addQuiz(int score) {
numberQuizes ++;
totalScores = totalScores + score;
}
public int getTotalScore() {
return totalScores;
}
public int getCount() {
return numberQuizes;
}
public int getQuizAverage() {
QuizAverage = totalScores / numberQuizes;
return QuizAverage;
}
public static void main(String[] args) {
//This program intakes quiz scores from a dialog box and averages them before informs the user.
Students student = new Students();
Scanner in = new Scanner(System.in);
ArrayList score = new ArrayList<>();
boolean done = false;
do {
String input;
input = JOptionPane.showInputDialog("Enter Score(Click cancel or the X to quit.): ");
if(input == null) {
break;
}
student.addQuiz(Integer.parseInt(input));
score.add(input);
}while(!done);
System.out.println("Entered the following Scores: "+score);
System.out.println("Total Quizes Entered: "+student.getCount());
System.out.println("Quiz Average score for all quizes: "+student.getQuizAverage()+"%");
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
