hey guys! i'm having trouble adding some stuff from a loop to an array. hopefully someone can help me. i put a comment in my code to show where I'm having trouble
here's the assignment:
The Institute of Technology Termonfeckin requires a program to examine students and print out simple reports. Because some of the students in the college are very lazy, the examiners are never sure how many students will turn up at the exam, but there will be at least one. For each student that turns up, the college examines them in 3 subjects. Each subject mark must be entered and a message is printed telling the examiner if the student has gotten honours (75 or over), a pass (50 or over) or failed (under 50). The total marks for each subject is also stored. At the end of the examination when there are no more students, the program prints a short report including the number of students processed, the average mark for each subject and the highest average result from all the subjects.
1. Create a loop which processes at least one student (but could process any number) and ask the user at the end of it do they want to add another student true/false Done
2. Create a loop which examines each subject for each student Done
3. Allow the user to enter grades for students, and print a message about whether they have an honour, pass or fail Done
4. Create an array to hold the total marks in each subject, add the marks for each student’s grade into this array This is the part I'm having trouble with
5. When the loop is finished, print out how many students were processed Done
6. Print out the average mark for each subject (you may use a for loop)
7. Print out the best average mark of all the subjects
Below is an example of the output I should have when I'm done:
Welcome to the Institute of Technology Termonfeckin Exam Processing System
Please enter marks for subject 1 for student 1
100
The student has an honour in this subject
Please enter marks for subject 2 for student 1
75
The student has an honour in this subject
Please enter marks for subject 3 for student 1
50
The student has passed this subject
Do you want to add another student? true/false
true
Please enter marks for subject 1 for student 2
1
The student has failed this subject
Please enter marks for subject 2 for student 2
2
The student has failed this subject
Please enter marks for subject 3 for student 2
3
The student has failed this subject
Do you want to add another student? true/false
true
Please enter marks for subject 1 for student 3
40
The student has failed this subject
Please enter marks for subject 2 for student 3
56
The student has passed this subject
Please enter marks for subject 3 for student 3
78
The student has an honour in this subject
Do you want to add another student? true/false
false
There were 3 processed today
The average mark for subject 1 was 47.0
The average mark for subject 2 was 44.333333333333336
The average mark for subject 3 was 43.666666666666664
The best subject average was: 47.0 for subject 1
my code so far:
import java.util.Scanner; class CA2007 { public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.println("Welcome to the Institute of Technology Termonfeckin Exam Processing System"); double[] subject1 = { }; double[] subject2 = { }; double[] subject3 = { }; int processed = 0; boolean run = true; int student = 0; // needed for student number (student 1, student 2 etc) do // loop to process the students Q1 { processed ++; // used to output total students processed Q5 student ++; // needed for student number (student 1, student 2 etc) for(int i = 1; i <= 3; i++) // loop to process each of the 3 subjects Q2 { int mark = 0; System.out.println("Please enter marks for subject " + i + " for student " +student); mark = keyboard.nextInt(); [COLOR="Red"]// i need to add marks to each subject array here but because it's a loop i'm not sure how.. for example the first time the loop runs i need to add the int mark to to subject1, when the loop runs again i need to add mark to subject2 etc[/COLOR] if(mark >= 75) { System.out.println("The student has an honour in this subject"); } else if(mark >= 50) { System.out.println("The student has passed this subject"); } else if(mark < 50) { System.out.println("The student has failed this subject"); } } System.out.println("Do you want to add another student? true/false"); run = keyboard.nextBoolean(); } while(run == true); System.out.println("There were " +processed+ " students processed today"); // outputs total students processed by program Q5 } }
any help is appreciated!