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









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
final grade
a student?s final grade from 50-100. Evaluate the Final grade and display the Point...?s final grade from 50-100. Evaluate the Final grade and display the Point... final grade from 50-100. Evaluate the Final grade and display the Point
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
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
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 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
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  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
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();" />
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
method
method   how and where, we can define methods ? can u explain me with full programme and using comments
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
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
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
Adding an employee
Adding an employee  coding for adding an employee
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
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
Retrieve all the students in the same year(Java ArrayList)?
; } students- contains all the students in the DB (I used it in another method...Retrieve all the students in the same year(Java ArrayList)?  ...); if(search != null){//if found 1 student by year do{//Search all students
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
How to calculate area of rectangle
. To calculate the area of the rectangle define one method calculate which will calculate... method inside main method. The area will be calculated by calling the calculate... How to Calculate Area of Rectangle   
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
Code to calculate hair density
Code to calculate hair density  Hello, Would you please give me a code to calculate the hair density on scalp from image in java
calculate sum of individual digit
calculate sum of individual digit   How calculate product of first and last digit of indiviual numbers Like a=43278 4*8=32
calculate sum of individual digit
calculate sum of individual digit  Hi How to calculate product of first snd last digit of indiviual digit Like Num=23456 S=2*6
data science internships for international students
data science internships for international students  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: data science internships for international students Try to provide
ai courses for high school students
ai courses for high school students  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: ai courses for high school students Try to provide me good examples or tutorials
How to calculate days in a year
How to calculate days in a year  Hi, How to calculate no of days in a year? I want a program that calculates no of days in a year by specifying year a parameter. Thanks   Hi, Please check the thread example
How to calculate the average in Hibernate?
How to calculate the average in Hibernate?  Hi, I have to calculate the average in Hibernate. How to calculate the average in Hibernate? Thanks   Hi, You can use the project in Hibernate. Here is the example code
how to calculate max and min - RUP
how to calculate max and min  hye!i'm a new for the java and i want to ask a question . Could anyone help me to teach how to calculate the maximum... void main(String args[]) { // Method for the max number among the pair
Write a JSP program to display the grade of a student by accepting the marks of five subjects.
Write a JSP program to display the grade of a student by accepting the marks of five subjects.  Write a JSP program to display the grade of a student by accepting the marks of five subjects
Calculate factorial of a number.
Calculate factorial of a number.  How to calculate factorial of a given number?   import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Factorial { public static
Java: Adding Row in JTable
Java: Adding Row in JTable   how about if we already have the JTAble created earlier. And i just found nothing to get its DefaultTableModel, thus, I can't call insertRow() method. Is there any work around for this? I found
Calculate sum and Average in java
Calculate sum and Average in java  How to calculate sum and average in java program?   Example:- import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class AvarageTest
calculate a list of products
calculate a list of products  Hi can you help me with this java program. This program should allow the user to order from a small catalogue of three items displayed on the screen, then calculate the user's final bill, including
Internship in Delhi for Engineering Students
Internship in Delhi for Engineering Students Internship program in various software technologies for Engineering in Delhi & NCR. We are arranging the internship program in different software development technologies. All
ModuleNotFoundError: No module named 'date_calculate'
ModuleNotFoundError: No module named 'date_calculate'  Hi, My... named 'date_calculate' How to remove the ModuleNotFoundError: No module named 'date_calculate' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'latimes-calculate'
ModuleNotFoundError: No module named 'latimes-calculate'  Hi, My... named 'latimes-calculate' How to remove the ModuleNotFoundError: No module named 'latimes-calculate' error? Thanks   Hi, In your

Ads