Java Assignment one: Student Result processing system

Student result UML
Student Result processing

Create student result processing system with an abstract class. All years students data can be entered and displayed by inherited sub classes. Abstract class should contain student roll, name and registration number.

Aim: Students should have clear  understanding of basic java class with object oriented concepts. Abstract class  should  be  implemented in the assignment. Java basic terms  like Object, class, method, inheritance, function overloading  should be clear to the student.

Procedure:  An abstract class named student with its data member roll, name, registration number. Sub classes should inherit from the student class. Semester based students are enrolled with their subjects and subject credit. From the main class all the students result processed and displayed. Necessary member functions should be included in the classes.

Solution:

Code for Student class:

Student has name,roll and registration number as reg. Student name are String, roll and reg number are integer number. In the constructor we set name, roll and reg values by passing parameters. In student class, we have another function which is for mark to grade conversion. The function markToGrade takes mark as parameter and return the grade as float value.


package student.result;

public class Student {
String name;
int roll, reg;

public Student(String name, int roll, int reg) {
this.name = name;
this.roll = roll;
this.reg = reg;
}
public  float markToGrade(float mark){
float gradePoint;
if(mark>=80 && mark<=100)
gradePoint=(float) 4.0;
else if(mark>=75 && mark<=79)
gradePoint=(float) 3.75;
else if(mark>=70 && mark<=74)
gradePoint=(float) 3.50;
else if(mark>=65 && mark<=69)
gradePoint=(float) 3.25;
else if(mark>=60 && mark<=64)
gradePoint=(float) 3.00;
else if(mark>=55 && mark<=59)
gradePoint=(float) 2.75;
else if(mark>=50 && mark<=54)
gradePoint=(float) 2.50;
else if(mark>=45 && mark<=49)
gradePoint=(float) 2.25;
else if(mark>=40 && mark<=44)
gradePoint=(float) 2.00;
else
gradePoint=(float) 0.00;
return gradePoint;
}
}

In the program, we have to use interface called Result. Result interface  has calculateGpa, getSubject, showResult and setMarks functions which should be  implemented in implemented class.


package student.result;

public interface Result {
float calculateGpa();
void getSubject();
void showResult();
void setMarks(float mark1,float mark2);
}

FirstSemester class extends from student class and implements result interface. Here,subject1 as sub1 and subject2 as sub2 are String and mark, grade and credit are float property. calculateGpa, getSubject, showResult and setMarks functions are implemented here as it is from result interface. For calculateGpa we have to add multiplication of grade and credit and add it with grade


package student.result;

public class FirstSemester extends Student implements Result {
private String sub1, sub2;
private float mark1, mark2, grade1, grade2,credit1,credit2;

public FirstSemester(String name, int roll, int reg) {
super(name, roll, reg);

}
@Override
public void setMarks(float mark1,float mark2) {
this.mark1=mark1;
this.mark2=mark2;
this.grade1=markToGrade(mark1);
this.grade2=markToGrade(mark2);
}

@Override
public float calculateGpa() {
return (grade1* credit1+ grade2*credit2) / (credit1+credit2);
}

@Override
public void getSubject() {
sub1="Introduction to Computer System";
sub2="Structured Programming Language";
credit1=(float)2.0;
credit2=(float)3.0;
}

@Override
public void showResult() {
System.out.println("\nName: " + name + "\nRoll = " + roll + "\nRegistration no: " + reg + "\n" + sub1 + " grade: " + grade1+ "\n" + sub2 + " grade: " + grade2 + "\nGPA: " + calculateGpa());
}
}


package student.result;

public class SecondSemester extends Student implements Result {
private String sub1, sub2;
private Float mark1, mark2, grade1, grade2,credit1,credit2;

public SecondSemester(String name, int roll, int reg) {
super(name, roll, reg);
}
@Override
public void setMarks(float mark1,float mark2) {
this.mark1=mark1;
this.mark2=mark2;
this.grade1=markToGrade(mark1);
this.grade2=markToGrade(mark2);
}
@Override
public float calculateGpa() {
return (grade1* credit1+ grade2*credit2) / (credit1+credit2);
}

@Override
public void getSubject() {
sub1="Data Structure";
sub2="Discrete Mathematics";
credit1=(float)3.0;
credit2=(float)2.0;
}

@Override
public void showResult() {
System.out.println("\nName: " + name + "\nRoll = " + roll + "\nRegistration no: " + reg + "\n" + sub1 + " grade: " + grade1+ "\n" + sub2 + " grade: " + grade2 + "\nGPA: " + calculateGpa());
}
}


package student.result;

public class StudentResult {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
FirstSemester std1 = new FirstSemester("Shufol", 127, 149);
std1.setMarks(60,70);
System.out.println("\nEnter First Semester Student's Info:");
std1.getSubject();
std1.showResult();

SecondSemester std2 = new SecondSemester("Fakhrul", 227, 249);
std2.setMarks(70,80);
System.out.println("\n\nEnter Second Semester Student's Info:");
std2.getSubject();
std2.showResult();
}
}

 

download the project from here