Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


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

}


Advertisement
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
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
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
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
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
Adding an employee
Adding an employee  coding for adding an employee
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
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
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 time ..
calculate the time ..  [CODE] Elapsed Time Example <script type="text/javascript"> var startTime = null...="button" value="Calculate Difference" onclick="calculateTimeElapsed();" />
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
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
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
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 reward points.
calculate reward points.  How to calculate reward points in a multiplex automation system
calculate size of array
calculate size of array  Is it possible to calculate the size of array using pointers in Java
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
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 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
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
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
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 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 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
adding groups in contacts
adding groups in contacts  how to add groups in contacts using servlet and jsp????pls help.thanku in advance
adding view to viewcontroller
adding view to viewcontroller  How to add a frame window that opens on button click .. in iPhone application
javascript adding a value to an array
javascript adding a value to an array  How to add a value to a function argument or an array in JavaScript
Adding photo to iPhone simulator
Adding photo to iPhone simulator  Hi, there is no photo in my iPhone simulator.. how can i add one? Please suggest. Thanks
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
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
Dynamically adding textbox and labels
Dynamically adding textbox and labels  Sir, In my application I want to insert texbox and labels dynamically and want to insert database field value in that generated label. Plz help me, Thanks in advance
Adding Jar into Eclipse
Adding Jar into Eclipse  Hi, Please provide Step by step procedure to add jar, tld files and configurations in Eclipse Helios version and i am using Jboss5. Thanks&Regards, Shiva s
testcase for adding - JUNIT
testcase for adding  hi deepak...I am new to junit.can u send me a JUnit test case for adding or multiplying of two numbers.please i need it urgently
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
Adding images in itext pdf
Adding images in itext pdf  Hi, How to add image in pdf file using itext? Thanks   Hi, You can use following code: PdfWriter.getInstance(document,new FileOutputStream("imagesPDF.pdf")); Read more at Inserting
webservices adding in eclipse
webservices adding in eclipse  hi team, i am working on webservices, please guide me how to add webservices in eclispe with step by step and give some examples also.   Please visit the following link: http
Adding customitem in canvas in J2ME?
Adding customitem in canvas in J2ME?  In J2ME how should we add a customitem inside the canvas.Because i need to perform key event handling for customitem.The key event handling is allowed in canvas not in form.So i try to use
jtable-adding a row dynamically
jtable-adding a row dynamically  hi..i am doing a project for pharmacy .. *pblm:* when i want to enter the details in jtable while running the application there are 3 rows and 4 columns which is default bt when we we have
Calculate Entropy using C++
Calculate Entropy using C++  # include <iostream> # include <cmath> using namespace std; int main() { float S0,S1,S2,S3; float Hs,Hs3; float
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
 

 

 

DMCA.com