Results 1 to 15 of 15
  1. #1
    Christ90 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default calculate average letter grades...

    Hi, i have a problem. I am making a program that i want to calculate an average grade on a student depending on the grades that student gets.. A student will recieve multiple grades during a semester and all will be letter grades.. what I want to make is a method that can calculate the average grade from two variables... one to be int numberOfGrades and the other to be char gradeSum.. if a student gets 3 A's one semester the numberOfGrades would be 3 and the gradeSum will be 'A' + 'A' + 'A'.... How do i let the machine calculate the average of these three grades? Thanks for replies :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    It could sort work by adding chars casted to ints, but it's wrong-headed and will be prone to errors. My recommendation is that you not do this, that you treat numbers as numbers, including the sum. Create a method that converts a letter grade to a number, and then add those numbers. My preference would be to use doubles here not ints so your GPA is not limited to whole numbers.

  3. #3
    Christ90 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    I have gotten a school assignement that says i have to do it by chars and ints... therefore i cant convert them to ints.. could be a backup sollution but for me but to get a full score i cant do that.. Maybe you could give me an example of how you would cast it?
    Last edited by Christ90; 01-25-2010 at 12:02 AM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Christ90 View Post
    I have gotten a school assignement that says i have to do it by chars and ints... therefore i cant convert them to ints.. could be a backup sollution but for me but to get a full score i cant do that.. Maybe you could give me an example of how you would cast it?
    No, because it would be wrong. Please print your actual assignment, as I think you're misinterpreting it.

  5. #5
    Christ90 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    ssssssssssssssssssssss
    Last edited by Christ90; 01-25-2010 at 09:53 AM. Reason: Not sure i'm allowed to have this out on the internet.. Just in case

  6. #6
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    This is a pretty good idea to keep track of ones grade. I want to keep track of all my classes. I'm anticipating I can do it like this:

    Have an abstract class called Subject.
    Java Code:
    public abstract class Subject {
    	
    	private double[] tests;
    	private double[] quizzes;
    	private double[] homework;
    	
    	public void addTest(double grade) {
    		//implementation here
    	}
    	public void addQuiz(double grade) {
    		//implementation here
    	}
    	public void addHW(double grade) {
    		//implementation here
    	}
    	public abstract void calcGrade();
    	
    	public static String convertToLetterGrade(double grade) {
    		//implementation here
    	}
    }
    Classes like English, Math, Science, etc. would extend the Subject class. What do you guys think?
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  7. #7
    Christ90 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    That was the same as Fubarable said i think... As I said to him this would be a good backup but to get the assignment correct i will have to use char all the way through or as much as possible.. i know how to do it if i convert after input and before output.. but i wonder if anyone can show me how to do the math with char's... Thanks for the answer though :)

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  9. #9
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Fubarable, would the abstract class posted in #6 be a good idea?
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  10. #10
    Christ90 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    Yeah.. it is possible to add the chars but not sure how to get the answers to also be chars from A-F.. It seems java is using ASCII code or something for chars...

  11. #11
    Christ90 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Lil_Aziz1 View Post
    Fubarable, would the abstract class posted in #6 be a good idea?
    I think it is an good idea to do it that way Lil_Aziz1... but the thing is that my teacher has said a way to do and if its not that way it is not possible to get a full score.. Dont know why but that is the way it is :P

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Christ90 View Post
    Yeah.. it is possible to add the chars but not sure how to get the answers to also be chars from A-F.. It seems java is using ASCII code or something for chars...
    That's where you cast as a char:
    Java Code:
        char sum = 'A' + 'B' + 'C' + 'B';
        System.out.println((char)(sum/4));

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Lil_Aziz1 View Post
    Fubarable, would the abstract class posted in #6 be a good idea?
    Looks fine, though perhaps better is to use Lists rather than arrays, or even an interface rather than abstract class so that the fields can be whatever works best.

  14. #14
    Christ90 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    That's where you cast as a char:
    Java Code:
        char sum = 'A' + 'B' + 'C' + 'B';
        System.out.println((char)(sum/4));
    That should work:D will try to put it into the code now :) hope it works :D

  15. #15
    Christ90 is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    It worked perfectly now:) Thank you very much Fubaruble :)

Similar Threads

  1. Letter view
    By wide in forum NetBeans
    Replies: 1
    Last Post: 07-02-2009, 03:40 PM
  2. Array help counting # of grades
    By speaknspell in forum New To Java
    Replies: 4
    Last Post: 04-16-2009, 11:09 PM
  3. Printing Out Every Other Letter
    By Agent in forum New To Java
    Replies: 4
    Last Post: 11-20-2008, 01:43 AM
  4. Calculate Average
    By sthack99 in forum New To Java
    Replies: 4
    Last Post: 06-13-2008, 12:09 PM
  5. Calculate average age for women and men?
    By Legoland in forum New To Java
    Replies: 3
    Last Post: 04-18-2007, 11:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •