adding a method to calculate a students grade

 
 

Share on Google+Share on Google+

derek
adding a method to calculate a students grade
4 Answer(s)      6 years and 8 months ago
Posted in : Java Beginners

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();
    }

}

Ads
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
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
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  
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
Adding an employee
Adding an employee  coding for adding an employee
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
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
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
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
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
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
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
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();" />
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
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
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
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
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 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
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
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
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
method
method   how and where, we can define methods ? can u explain me with full programme and using comments
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
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

Ads

 
Advertisement null

Ads