Develop a Java program to allow computation of student marks in Eng, Math, Chem, Geo, and Physics. The teacher can enter marks for any number of students. He/she can press ‘E’ on the keyboard to stop entering marks. All marks should be stored in an array. When teacher presses E, the program computes and displays total marks, average, highest mark and lowest mark for each student. Use appropriate math functions for average, highest mark, lowest mark, a function which will be called every time the teacher needs to continue putting in marks, and control structures to guide the flow of the program.
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
class Student{
public double [] marks = new double[5];
public Student(double[] marks) {
this.marks = marks;
}
public void CalcMark(){
double totalMarks = 0;
double highestMark = 0;
double lowestMark = marks[0];
for (double v : marks) {
totalMarks += v;
if(highestMark < v){
highestMark = v;
}
if(lowestMark > v){
lowestMark = v;
}
}
double average = totalMarks / 5.0;
System.out.println(totalMarks);
System.out.println(average);
System.out.println(highestMark);
System.out.println(lowestMark);
}
}
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
char ch;
double[] marks = new double[5];
ArrayList<Student> list = new ArrayList<Student>();
do {
for(int i = 0; i < 5; i++){
marks[i] = in.nextDouble();
}
list.add(new Student(marks));
System.out.print("Exit? Enter E: ");
ch = (char) System.in.read();
} while (ch != 'E');
int c = 0;
for (Student s : list) {
System.out.println("Student " + ++c);
s.CalcMark();
}
}
}
Comments
Leave a comment