1st class
public class Student {
private String name;
private double id, examMark, courseMark, totalMark,grade;
Student(String name,double id,double examMark,double courseMark){
this.name=name;
this.id=id;
this.examMark=examMark;
this.courseMark=courseMark;
this.totalMark=getMark(getExammark(),getCoursemark());
this.grade=grade;
}
public String getName()// to return name of student
{
return name;
}
public double getID()//to return id of the student
{
return id;
}
public double getExammark() // return exammark of the student
{
return examMark;
}
public double getCoursemark()// return coursemark of the mark
{
return courseMark;
}
public void print()
{
System.out.println("ID: " + id);
System.out.println("ExamMark: " + examMark);
System.out.println("CourseMark: " + courseMark);
System.out.println("Total Mark:"+ totalMark);
System.out.println("Grade:"+ grade);
}
// to return total mark of student
public double getMark(double courseMark, double examMark)
{
if(courseMark<50)
{
if(examMark<courseMark)
{
return examMark;
}
else
{
return courseMark;
}
}
else if(examMark<50)
{
return examMark;
}
else
{
return (courseMark+examMark)/2;
}
}
// to return student grade
public String getGrade()
{
if(totalMark>=0 && totalMark<50)
return "NN";
else if (totalMark>=50 && totalMark<60)
return "PA";
else if (totalMark>=60 && totalMark<70)
return "CR";
else if (totalMark>=70 && totalMark<80)
return "DI";
else if (totalMark>=80 && totalMark<100)
return "HD";
else return "OUT OF RANGE";
}
// to set student’s exam mark
public void setExamMark (double examMark) {
this.examMark=examMark;
this.totalMark=getMark(getExammark(),getCoursemark());
}
// to set student’s course mark
public void setCourseMark (double courseMark){
this.courseMark=courseMark;
this.totalMark=getMark(getExammark(),getCoursemark());
}
}
2nd class
import java.util.*;
public class TestStudent{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
List<Student> studentsList = new ArrayList<Student>();
int temp,option;
double examMark=-1,courseMark=-1;
System.out.println("Please enter number of student marks you would like to add");
temp = input.nextInt();
for (int i=0;i<temp;i++){
System.out.println("Please enter student name:");
String name=input.next();
System.out.println("Please enter student id:");
int id=input.nextInt();
examMark=-1;
courseMark=-1;
while(examMark>100 || examMark<0){
System.out.println("Please enter exam mark:");
examMark=input.nextDouble();
}
while(courseMark>100 || courseMark<0){
System.out.println("Please enter course mark:");
courseMark=input.nextDouble();
}
studentsList.add( new Student(name,id,examMark,courseMark));
}
do{
System.out.println("Welcome to Grade Calculation System");
System.out.println("----------------------------------------");
System.out.println("");
System.out.println("1. Display a Student Mark");
System.out.println("2. Change Student Mark");
System.out.println("3. Print out information for all students");
System.out.println("4. Exit program");
option=input.nextInt();
switch (option)
{
case 1:
System.out.println("1. Display a Student Mark");
System.out.println("Please enter name of student you would display mark for ");
String name = input.next();
for(Student s: list){
System.out.println("ID:"+s.getID()+"\t");
System.out.println("Exam Mark:"+s.getExammark());
System.out.println("Course Mark:"+s.getCoursemark());
System.out.println("Total Mark:"+s.getMark()+"%");
System.out.println("Grade:"+s.getGrade());
}
break;
case 2:
System.out.println("Please enter student name:");
name = input.next();
if (s.getName() == name)
{
System.out.println("Please enter exam mark: " + s.getName().ToString()+": ");
System.out.println("Please enter course mark: " + s.getName().ToString()+": ");
System.out.println("Marks Changed");
}
else{
System.out.println("Invalid Entry! Marks must be between 0 - 100!");
}
break;
case 3:
for(Student s: list){
System.out.println(s.getName()+"\t"+s.getID()+"\t"+s.getExammark()+"\t"+s.getCoursemark());
}
break;
}
if(option == 4) break;
}
while (true);
}
}
i think i got a lot of mistake in it but at least i try, so my question is how do i store it and called up them?