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 gradeadding 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 studentsthe
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
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
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 assesmentJava 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 studentscreate 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 loopadding 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 listarray 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 averagecalculate 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 averagecalculate 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 studentsinternships 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
methodmethod 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 a dialogueadding 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 arraycalculate size of array Is it possible to
calculate the size of array using pointers in Java
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 hourcalculate 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 densityCode to
calculate hair density Hello,
Would you please give me a code to
calculate the hair density on scalp from image in java
data science internships for international studentsdata 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 studentsai 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 yearHow 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 - RUPhow 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
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 javaCalculate 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 productscalculate 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 StudentsInternship 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