Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to calculate GPA

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    44
    Thanks
    9
    Thanked 2 Times in 1 Post

    Default How to calculate GPA

    This is what I need to do.
    When user type “grade,111111111,11111,A” assign a grade of A to the student, with RUID of 111111111, against course, with index of 11111.
    4.1 View class will handle input and call CourseRegistrationController singleton object to get things done.
    4.2 CourseRegistrationController.grade method will
    4.2.1 First to call CourseOfferingContoller.getCourse method to get the Course object with index number of 11111.
    4.2.2 It then call Course.grade method to assign grade to student with RUID of 111111111.
    4.3 Course.grade method will get the Enrollment object from its Hashtable, with RUID of 111111111. And call Enrollment.setGrade to change the grade.

    I have done all this, but kind of stuck of what to do next

    Here is the last step 4.3
    	// assign a grade to a student through 
    	// roster list
    public Enrollment grade(String RUID, String grade){
    		Enrollment g = (Enrollment) enrollments.get(RUID);
    		 g.setGrade(grade);
     
    		return null;


    enrollment class
    public void setGrade(String grade) {
    		this.grade = grade;
    	}
    	public String getGrade() {
    		// when assign a grade to a student
    		// you also need to recalculate GPA
     
     
    		return grade;
    	}

    Im stuck on the "to change the grade." part. I am not sure where I store the grade for each course. I have 4 hash tables, one stores all the courses( index is course id and object is course name) one stores all students( index is student id and object is student name) one stores all the students in a class( index is course id and object is student name) and the other stores all the classes the one student is in. ( index is student id and object is course name)
    But does not seem right.

    In the course class, it has the method grade which says it // assign a grade to a student through roster list, but I don't see how since the index for that hashtable is the course id. How would I be able to find a particular student in the hashtable? Also how would I go about adding this grade? I was thinking something like this

    	public Enrollment grade(String RUID, String grade){
    		Enrollment g = (Enrollment) enrollments.get(RUID);
    		 g.setGrade(grade);
    		 enrollments.put(g.getCourse(), g );
    		return null;

    Then the gpa is stored in the hashtable with index being student id, but not sure how I would be able to view the grades in the other hashtable. I would assume using the enrollments.get but i am lost. To me it seems like it would be easier to just make another hashtable for grades and somehow have them linked or something. idk I am just confused.

    thanks


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: How to calculate GPA

    I'm curious: does the project constraints force you to avoid Objects as much as possible? It seems to me that you can turn those 4 hashtables into 2 by creating a Student object and a Course object.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    44
    Thanks
    9
    Thanked 2 Times in 1 Post

    Default Re: How to calculate GPA

    Our professor told us to make 4 hashtables. I just don't really understand why but w.e lol

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: How to calculate GPA

    Ok, so to understand the four hashtables, is this what it is set up like?
    Key             Object
    Course_ID     Course_Name(String)
    Student_ID    Student_Name(String)
    Course_ID     Student_Name(String)
    Student_ID    Course_Name(String)

    Apparently there is a Course class, and you have an Enrollment class. Where are these objects stored?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Member
    Join Date
    Oct 2012
    Posts
    44
    Thanks
    9
    Thanked 2 Times in 1 Post

    Default Re: How to calculate GPA

    CourseOfferings class has the first hashtable you listed
    StudentRecords class has second
    course class has the third one
    and student class has the fourth one
    I have 8 classes in total with 3 packages, controller , view class model. theirs 3 classes in the controller 1 in view and 5 in model

    was talking to a class mate and they said that

    this already sets the grade into the has table, this is in the course class
    public Enrollment grade(String RUID, String grade){
    		Enrollment g = (Enrollment) enrollments.get(RUID);
    		 g.setGrade(grade);
    		return null;
    does it seem right?

    Here is my course class
    String index;
    	String name;
    	// store roster list
    		Hashtable enrollments= new Hashtable();
     
     
     
        public Course(String index, String name){
        	this.index = index;
        	this.name = name;
     
        }
     
    	public String getIndex() {
    		return index;
    	}
     
    	public String getName() {
    		return name;
    	}
     
     
    	// add an enrollment to roster list
    	public Enrollment addEnrollment(Enrollment e) {
    		//put enrollment in hashtable
    		enrollments.put(e.getCourse(), e );
    		return e;
     
     
    	}
     
    	// remove an enrollment from roster list
    	public Enrollment removeEnrollment(String RUID) {
     
    		 enrollments.remove(RUID);
    		return null;
    	}
    		// assign a grade to a student through 
    	// roster list
    	public Enrollment grade(String RUID, String grade){
    		Enrollment g = (Enrollment) enrollments.get(RUID);
    		 g.setGrade(grade);
    			return null;
     
    	}
     
     
    }

Similar Threads

  1. Need some ideas on how to calculate this
    By derekxec in forum Java Theory & Questions
    Replies: 3
    Last Post: July 2nd, 2012, 06:50 PM
  2. GPA Calculation Program using an input file
    By ddk1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 6th, 2011, 06:28 AM
  3. Cannot calculate. Please help me....
    By safarina02 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 15th, 2011, 01:11 PM
  4. Calculate primes help
    By TommyFiz in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 27th, 2009, 11:41 PM
  5. GPA calc code... HELP
    By ber1023 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 13th, 2009, 11:20 PM