adding a method to calculate a students grade

adding a method to calculate a students grade

The Following program which displays a students name, id and mark works fine. But when i tried to add a method to display the grade based on the mark of the student i cant seem to get it working. i'm sure it is an easy fix but i cant seem to figure it out. can someone help please the program code is as follows:

class Student { private int studentID; private String name; private float mark; private char grade;

public Student(int theStudentID, String theName)
{
    studentID = theStudentID;
    name = theName;

}

public void setStudentID(int theStudentID)
{
    studentID = theStudentID;
}

public void setName(String theName)
{
    name = theName;

}

public void setMark(float theMark)
{
    mark = theMark;
}

/* ------------THIS METHOD COULD BE THE PROBLEM---------------*/ public void setGrade(char theGrade) {

    grade = theGrade;
}



public int getStudentID()
{
    return studentID;
}

public String getName()
{
    return name;
}

public float getMark()
{
    return mark;
}

/* ------------THIS METHOD COULD BE THE PROBLEM---------------*/

public char getGrade()
{


        if((mark > 70) && (mark <= 100))
                                grade = 'A';
        else if ((mark > 60) && (mark <= 70))
                                grade = 'B';
        else if ((mark > 50) && (mark <= 60))
                                grade = 'C';
        else if ((mark > 40) && (mark <= 50))
                                grade = 'D';
        else

        grade = 'E';

        return grade;
}


public void display()
{
    System.out.println("Student ID is " + studentID);
    System.out.println("Student name is " + name);
    System.out.println("Student mark is " + mark);
    System.out.println("Student grade is " + grade);
}

public static void main (String [] args)
    {

        Student student1 = new Student(1, "mary Dee");
        Student student2 = new Student(2, "john doo");
        Student student3 = new Student(3, "Bart Bloggs");

        student1.setMark(90.4f);
        student2.setMark(55.0f);
        student3.setMark(73.4f);


        student1.display();
        student2.display();
        student3.display();
    }

}

View Answers

April 13, 2011 at 5:59 AM

class Student { private int studentID; private String name; private float mark; private char grade; public Student(int theStudentID, String theName) { studentID = theStudentID; name = theName;

} public int getStudentID() { return studentID; } public String getName() { return name; }

public void setMark(float themark) { mark = themark; } public float getMark(){ return mark;

} public void setGrade(char theGrade) {

grade = theGrade;

} /* ------------THIS METHOD COULD BE THE PROBLEM---------------*/

public char getGrade() {

    if((mark > 70) && (mark <= 100))
                            grade = 'A';
    else if ((mark > 60) && (mark <= 70))
                            grade = 'B';
    else if ((mark > 50) && (mark <= 60))
                            grade = 'C';
    else if ((mark > 40) && (mark <= 50))
                            grade = 'D';
    else

    grade = 'E';

    return grade;

}

public void display() { System.out.println("Student ID is " + studentID); System.out.println("Student name is " + name); System.out.println("Student mark is " + mark); System.out.println("Student grade is " + grade); }

public static void main (String [] args) {

    Student student1 = new Student(1, "mary Dee");
    Student student2 = new Student(2, "john doo");
    Student student3 = new Student(3, "Bart Bloggs");

    student1.setMark(90.4f);
    student2.setMark(55.0f);
    student3.setMark(73.4f);
    student1.getGrade();
    student2.getGrade();
    student3.getGrade();


    student1.display();
    student2.display();
    student3.display();
}

}


April 13, 2011 at 6:06 AM

hopefully it will work.cheers mate


April 13, 2011 at 10:49 AM

class Student {
    private int studentID;
    private String name;
    private float mark;
    private char grade;

public Student(int theStudentID, String theName)
{
    studentID = theStudentID;
    name = theName;

}

public void setStudentID(int theStudentID)
{
    studentID = theStudentID;
}

public void setName(String theName)
{
    name = theName;

}

public void setMark(float theMark)
{
    mark = theMark;
}

 public void setGrade(char theGrade) {

    grade = theGrade;
}



public int getStudentID()
{
    return studentID;
}

public String getName()
{
    return name;
}

public float getMark()
{
    return mark;
}


public char getGrade()
{


        if((mark > 70) && (mark <= 100))
                                grade = 'A';
        else if ((mark > 60) && (mark <= 70))
                                grade = 'B';
        else if ((mark > 50) && (mark <= 60))
                                grade = 'C';
        else if ((mark > 40) && (mark <= 50))
                                grade = 'D';
        else

        grade = 'E';

        return grade;
}


public void display()
{
    System.out.println("Student ID is " + studentID);
    System.out.println("Student name is " + name);
    System.out.println("Student mark is " + mark);
    System.out.println("Student grade is " + grade);
}

public static void main (String [] args)
    {

        Student student1 = new Student(1, "mary Dee");
        Student student2 = new Student(2, "john doo");
        Student student3 = new Student(3, "Bart Bloggs");

        student1.setMark(90.4f);
        student2.setMark(55.0f);
        student3.setMark(73.4f);
         student1.getGrade();
         student2.getGrade();
         student3.getGrade();


        student1.display();
        student2.display();
        student3.display();
    }

}

April 13, 2011 at 4:39 PM

Thanks for help , works fine now

Ads









Related Tutorials/Questions & Answers:
adding a method to calculate a students grade
adding a method to calculate a students grade  The Following program... a method to display the grade based on the mark of the student i cant seem... theGrade) { grade = theGrade; } /* ------------THIS METHOD COULD BE THE PROBLEM
the grade of students
the grade of students  Write a Java program that prompt user to input a number of students in a class. Then, prompt user to input the student√Ę‚?¨‚?Ęs programming mark. Determine how many student get A+ and A for their grade
Advertisements
calculate volume of cube, cylinder and rectangular box using method overloading in java
calculate volume of cube, cylinder and rectangular box using method overloading in java  calculate volume of cube, cylinder and rectangular box using method overloading in java   calculate volume of cube, cylinder
Highest average score among 25 students
the user to enter grades of 25 students in a class and grade them into 4 lessons... again the grade) calculate average per student and will calculate the highest average among students who should be printed. how can i solve this problem
write a program to calculate volume of a cube, cylinder, rectangular box using method overloading
write a program to calculate volume of a cube  write a program to calculate volume of a cube, cylinder, rectangular box using method overloading  
ModuleNotFoundError: No module named 'grade'
ModuleNotFoundError: No module named 'grade'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'grade' How to remove the ModuleNotFoundError: No module named 'grade'
ModuleNotFoundError: No module named 'grade'
ModuleNotFoundError: No module named 'grade'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'grade' How to remove the ModuleNotFoundError: No module named 'grade'
Java programs on students assesment
Java programs on students assesment  1) Write a Java program... subject marks. (v) Follow the table for grading: Average of Marks Grade < 40...) Output the Student name, Student id, subject marks, average mark and the grade
Java example to calculate the execution time
Java example to calculate the execution time  ... will describe you the way that how one can calculate or get the execution time of a method or program in java. This can be done by subtracting the starting time
adding loop
adding loop  Hi I have a program that is not compiling when I add...)); list.add(new HardwareItems("M93","Sandpaper,fine grade",10.25)); list.add(new HardwareItems("M94","Sandpaper,fine grade",14.75
How to calculate attending hours?
How to calculate attending hours?  I need to calculate attending hours of a employee in a day in my project to make their monthly salary . By using... other method
create examination slip for students
create examination slip for students  hello,can anyone help me how to create examination slip that include subject code,courses,credit hours,grade ,and status
calculate average
calculate average  Question 2 cont.d Test case c: home works/labs 10 9 9 9 10 10 9 9 10 10 9 9 10 test scores: 65 89 note, the program should work with different numbers of home works/labs
array of students with marks list
array of students with marks list  There are 4 array of numbers... students have got against each examination. The order of students remain same across all lists and also the number of students (4 in this case). Marks List 1
calculate average
calculate average   Design and write a java program to determine all three digit numbers such that the sum of the cubes of the digits is equal... and write a program and calculate your final average in this course. The details
calculate the time ..
calculate the time ..  [CODE] Elapsed Time Example <script type="text/javascript"> var startTime = null...="button" value="Calculate Difference" onclick="calculateTimeElapsed();" />
Write a program to display grade message according to the marks
of students and their marks and display the grade according to student's marks... is a code that accepts the number of students and their marks and display the grade...Write a program to display grade message according to the marks  pls
Adding an employee
Adding an employee  coding for adding an employee
internships for data science students
internships for data science students  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: internships for data science students Try to provide me good examples
adding a dialogue
adding a dialogue  Blockquote Hi can you help with the program below,the program is a loop that prints out a code and a quantity when prompt for the user input.what I need is to modify the code to incorporate a dialogue asking
method
method   how and where, we can define methods ? can u explain me with full programme and using comments
calculate size of array
calculate size of array  Is it possible to calculate the size of array using pointers in Java
calculate reward points.
calculate reward points.  How to calculate reward points in a multiplex automation system
method
method  can you tell me how to write an abstract method called ucapan() for B2 class class A2{ void hello(){ system.out.println("hello from A2"); }} class B2 extends A2{ void hello(){ system.out.println("hello from B2
How to calculate area of rectangle
rectangle method which takes two parameters of type integer. To calculate the area of the rectangle define one method calculate which will calculate the area... main method. The area will be calculated by calling the calculate method inside
ModuleNotFoundError: No module named 'calculate'
ModuleNotFoundError: No module named 'calculate'  Hi, My Python... 'calculate' How to remove the ModuleNotFoundError: No module named 'calculate' error? Thanks   Hi, In your python environment you
calculate working hour
calculate working hour  why echo not come out? <html><body> <form action="<?php $_SERVER['PHP_SELF'];?>" method="post"> Working hour : <input name="workout" type="text"/><input name="submit1
ModuleNotFoundError: No module named 'grade-change-emailer'
ModuleNotFoundError: No module named 'grade-change-emailer'  Hi...: No module named 'grade-change-emailer' How to remove the ModuleNotFoundError: No module named 'grade-change-emailer' error? Thanks   Hi
ModuleNotFoundError: No module named 'UW-Grade-Conversion-Calculator'
ModuleNotFoundError: No module named 'UW-Grade-Conversion-Calculator' ...: No module named 'UW-Grade-Conversion-Calculator' How to remove the ModuleNotFoundError: No module named 'UW-Grade-Conversion-Calculator' error
ModuleNotFoundError: No module named 'grade-change-emailer'
ModuleNotFoundError: No module named 'grade-change-emailer'  Hi...: No module named 'grade-change-emailer' How to remove the ModuleNotFoundError: No module named 'grade-change-emailer' error? Thanks   Hi
ModuleNotFoundError: No module named 'ml_easy_peer_grade'
ModuleNotFoundError: No module named 'ml_easy_peer_grade'  Hi, My... named 'ml_easy_peer_grade' How to remove the ModuleNotFoundError: No module named 'ml_easy_peer_grade' error? Thanks   Hi, In your

Ads