Home Answers Viewqa Java-Beginners adding a method to calculate a students grade

 
 


derek
adding a method to calculate a students grade
4 Answer(s)      2 years and a month 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();
    }

}

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 Pages:
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
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
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
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
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
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
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
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 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
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
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?
How to solve this java code by adding the student marks not in the list... totalMarks; String grade; public void setTotalMarks(double totalMarks... totalMarks; } public void setGrade(String grade) { this.grade = grade
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
adding of two numbers in designing of frame
adding of two numbers in designing of frame  hello sir, now i'm create two textfield for mark1&mark2 from db.how to add these two numbers...("Calculate"); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver
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 the Sum of three Numbers
Calculate the Sum of Three Numbers   ... . In this section you will learn how to calculate the sum of three numbers by using three... how to calculate three integer number . First of all define class name "
Calculate factorial Using Recursion
Calculate factorial Using Recursion  ... through this example you will be understand how you can calculate the factorial... recursively is to imagine that your method does what it says.  To make
How to calculate area of triangle
the area of triangle define the method triangle which will calculate the area... .style1 { margin-right: 0px; } How to Calculate...; In this section we will learn how to calculate area of triangle. We
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  
Calculate process time in Java
Calculate process time in Java       This section provides the facility to calculate...: System.currentTimeMillis(): This is the method of the System class, which
Write a program to calculate area and perimeter of a circle
example will teach you the method for preparing a program to calculate the area... Write a program to calculate area and perimeter of a circle... of circle" in the System.out.println method.  Now use the parseInt
Having a hard time writing program to calculate test scores..........
Having a hard time writing program to calculate test scores.......... ... school is giving a standardized test to all of its students. There are 50... the students performed. Scores can range anywhere from 0 to 50. All
Calculate total number of elements remaining in the buffer.
Calculate total number of elements remaining in the buffer. In this tutorial, we will discuss how to calculate total number of elements remaining... Method Description static IntBuffer allocate( int capacity
c++ array find the average mark, highest mark, lowest mark, number of students passing,
c++ array find the average mark, highest mark, lowest mark, number of students passing,    i need help in adding the c++ code for the average mark, highest mark, lowest mark, number of students passing, using array. 01
c++ array find the average mark, highest mark, lowest mark, number of students passing,
c++ array find the average mark, highest mark, lowest mark, number of students passing,    i need help in adding the c++ code for the average mark, highest mark, lowest mark, number of students passing, using array. 01
how can i calculate loan - Java Interview Questions
how can i calculate loan  negotiating a consumer loan is not always... by 18, which is 55.66. this method of calculation may not be too bad if the consumer.... the program should then calculate the face value required in order
Adding an employee
Adding an employee  coding for adding an employee
object and method
offered to students. initially only three courses are involved. each courses has a code, a name, students enrolled, a current number of student, a maximum number of students allowed (quota) which is 10. a user should be able to add\drop
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
private method
private method  how can define private method in a class and using...=breadth; } public int calculate(){ int size; size=length*breadth; return(size...; this.breadth=b; } private int calculate(){ int size
Write a program to calculate factorial of any given number
Factorial Examples - Java Factorial Example to calculate factorial of any... program to calculate factorial of any given number. First of all define a class... the ParseInt method for converting the parses the string argument to a decimal integer
How to calculate area of Circle
How to Calculate Area of Circle       In this tutorial you will learn the method... method. First of all, we have to define class name "StaticCircle"
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
Adding a Rollover and Pressed Icon to a JButton Component in Java
Adding a Rollover and Pressed Icon to a JButton Component in Java... about adding event i.e. the rollover and click icon to a JButton component of swing...: button.setRolloverIcon(Icon icon_name): This is the method of the JButton class which is used
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();" />
private method
private method  how can define private method in a class and using...=breadth; } public int calculate(){ int size; size=length*breadth; return(size...; } public int calculate(){ int size; size=length*breadth
Adding time span example
Adding time span example     ... with the use of add() method of Calendar class which is available in the java.util package. We can add the time spans with the use of add() method which takes two
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
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 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
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
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
Write a program that makes use of a class called Employee that will calculate an employee's weekly paycheque.
Write a program that makes use of a class called Employee that will calculate... of a class called Employee that will calculate an employee's weekly paycheque. Design... and can be retrieved using the static method getCount( ) The constructor
Adding attributes to the string
Adding attributes to the string In this section, you will learn how to add... as the attributes. The method addAttribute() of AttributedString class add..., we have used the method drawString() of Graphics2D. Grpahics2D: 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.