Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Student {
- public static void main(String args[]) throws IOException
- {
- Scanner scan = new Scanner(System.in);
- Scanner file = new Scanner(new File("FinalExamDataFile.txt"));
- List<String> FirstName = new ArrayList<String>();
- List<String> LastName = new ArrayList<String>();
- List<String> IDNumber = new ArrayList<String>();
- List<Integer> Average = new ArrayList<Integer>();
- //initiating all of the counters in the program
- int j;
- int above70 = 0;
- int below70 = 0;
- //counters for the for loops
- int average = 0;
- for(int i=0; i<2; i++){
- int sum = 0;
- System.out.println("Enter the Student's first name");
- FirstName.add(scan.next());
- System.out.println("Enter the student's last name");
- LastName.add(scan.next());
- System.out.println("Enter the student's ID number");
- IDNumber.add(scan.next());
- System.out.println("Enter up to 15 grades, enter -1 to finish.");
- //adds up all 15 grades then divides them by 15 to get the student's average
- for(j=0; j<3; j++){
- int score = scan.nextInt();
- if (score > 100)
- {
- System.out.println("The score must be between 0-100");
- j--;
- }
- else if (score >= 0){
- sum = sum + score;
- }
- else if (score <= 0){
- System.out.println("The score must be between 0-100");
- j--;
- }
- else if (score == -1)
- {
- System.out.println("Thank you.");
- break;
- }
- }
- //takes the average of the 15 grades and adds to the "average" array
- Average.add(sum / j);
- if(sum/j >= 70){
- above70++;
- }
- else{ below70++; }
- }
- //allows user to call on a student to see their grade
- for(int k=0; k < k+1; k++){
- System.out.println("Enter the student's first name, last name, or ID Number to see their results");
- String search = scan.next();
- int index;
- index = FirstName.indexOf(search);
- index = LastName.indexOf(search);
- index = IDNumber.indexOf(search);
- if(FirstName.contains(search) || LastName.contains(search) || IDNumber.contains(search)){
- System.out.println("Student: " + FirstName.get(index) + " " + LastName.get(index) + " " +
- IDNumber.get(index) + "\nStudent's Average: " + Average.get(index));
- }
- else{
- System.out.println("The student was not found.");
- }
- }
- //reading the file goes here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement