Sahil-Pattni
1/27/2017 - 9:28 PM

Student Grading

Student Grading

/**
 * CS 180 - Lab 04 - Student
 *
 * Grading system for ASTR 102
 *
 * @author spattni <spattni@purdue.edu>
 *
 * @Lab L16
 *
 * @version 1/27/17
 */

public class Student
{
    private String id;
    private String dept;
    private int part;
    private int abs;
    private int exam;

    /**
     * Student class constructor: Creates a new instance of the Student Class, initializes instance variables with
     * the given arguments:
     *
     * @param id - the student's ID
     * @param dept - the student's dept
     * @param abs - the student's abs
     * @param exam - the student's exams grades
     * @param part - the student's participation
     */

    public Student(String id, String dept, int abs, int exam, int part)
    {
        this.id = id;
        this.dept = dept;
        this.abs = abs;
        this.exam = exam;
        this.part = part;
    }

    public int getOverallScore()
    {
        int totalScore = this.part + this.exam;

        if (this.abs == 0)
            totalScore+=2;

        return totalScore;
    }

    /**
     *
     * @param score overall score
     * @return LetterGrade
     */

    public String getLetterGrade(int score)
    {
        String letterGrade = "";

        if(this.abs >= 5)
            letterGrade = "F";
        else if(score >= 95 && this.exam <=100)
            letterGrade = "A+";
        else if(score >= 90 && this.exam <= 94)
            letterGrade = "A";
        else if(score >= 80 && this.exam <=89)
            letterGrade = "B";
        else if(score >= 70 && this.exam <=79)
            letterGrade = "C";
        else if(score >= 60 && this.exam <=69)
            letterGrade = "D";
        else if(score < 60)
            letterGrade = "F";

        return letterGrade;
    }

    public boolean hasPassedCourse(String letterGrade)
    {
        boolean hasPassed = false;
        if (this.dept.equalsIgnoreCase("PH"))
        {
            hasPassed = letterGrade.equals("A+") || letterGrade.equals("A") || letterGrade.equals("B");
        }
        else if (this.dept.equalsIgnoreCase("CS"))
        {
            hasPassed = letterGrade.equals("A+") || letterGrade.equals("A") || letterGrade.equals("B") || letterGrade.equals("C")
                    || letterGrade.equals("D");
        }
        return hasPassed;
    }

    public static void main(String[] args)
    {
        Student s = new Student("102011", "CS", 4, 55, 5);

        int totScore = s.getOverallScore();
        String grade = s.getLetterGrade(totScore);
        boolean result = s.hasPassedCourse(grade);

        System.out.println(s.id);
        System.out.println("Score: " + totScore);
        System.out.println("Grade: " + grade);

        if (result)
            System.out.println("Student " + s.id + " has passed the course");
        else
            System.out.println("Student " + s.id + " has failed the course");
    }
}