Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ultra noob.. Java Programming, CAO system

Options
  • 11-01-2011 2:02pm
    #1
    Registered Users Posts: 51 ✭✭


    Okay I have a problem and I knew it wouldn't work when I coded it but did it anyway to make it more understandable.

    A part of my assignment is to calculate the students leaving certificate points. Brief description of what I want to achieve is: I have my class Subject. In here it gets the grade and level taken. In my main I'm using an array to enter the 6 subjects which the user enters 'h' or 'l' for the level and enters the grade received for that subject.
    My problem is, I also need a method "public boolean isQualified(){ }"
    The program then should be able to calculate what course the student gets offered between Management Science/Computer Science/Business and Computing/Computer&Linguistics. I was wondering if it's possible to have a method to be able to calculate the total points.

    here's extracts of my code.

    public int getPoints(){

    if(level == 'h' && getLetGrade() == 'a' && getNumGrade() == 1){ // higher a1
    points = 100;
    }
    else if(level == 'l' && getLetGrade() == 'a' && getNumGrade() == 1 ){
    points = 60;
    }
    else if(level == 'h' && getLetGrade() == 'a' && getNumGrade() == 2){ /* higher a2*/
    points = 90;
    }
    else if(level == 'l' && getLetGrade() == 'a' && getNumGrade() == 2){
    points = 50;
    }
    return points;
    }
    // that goes all the way down to F

    in my main class, when it gets down to entering the students Leaving Cert details.
    **im using my colleges library package console**

    int points = 0;
    int i = 0;
    subject = new Subject[6];
    for(i = 0; i<subject.length; i++){
    subjectTaken = terminal.readString("Subject taken: ");
    levelTaken = terminal.readChar("Level taken: ");
    letterGrade = terminal.readChar("Letter grade received: ");
    numGrade = terminal.readInt("Number grade received: ");
    subject = new Subject(subjectTaken, levelTaken, letterGrade, numGrade);
    points = points + subject.getPoints();
    }
    terminal.println("Student received "+points+" points in the LC.");


    I also cheated a little bit in the main program as an example of what I want it to say. Obviously I've more requirements to add to certain courses, like Higher Maths and such but I just want to get the points bit working first.

    if(points > 390 && higherCount >=4){
    terminal.println("You got into MSISS in TCD");
    }
    else if(points >= 385 && points < 390 && higherCount >= 4){
    terminal.println("You got into Business and Computing in TCD");
    }
    else if(points >= 355 && points < 385 && higherCount >= 4){
    terminal.println("You got into Computer Science in TCD");
    }
    else if(points < 355 && points > 305 && higherCount >=4){
    terminal.println("You got into csll in TCD");
    }
    else{
    terminal.println("Ineligible for any course");
    }
    }
    }

    ** also I'm aware of the hard coding and how tedious it looks when getting the points for one subject, if there is a nice tip out there I'd appreciate it:)
    Apologies if I've gone about asking this question the complete wrong way.


Comments

  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,646 Mod ✭✭✭✭TrueDub


    Where do you need to add the method, in the Subject class, or in the main class?

    Essentially that method needs to examine the students total points and determine if that those points are equal to or above the points threshold for that course.


  • Registered Users Posts: 2,265 ✭✭✭Seifer


    Just some tips on the last block of if statements:
    If someone gets 390 points they won't get a course.
    The less than checks in the middle e.g. points < 385 are redundant.
    higherCount >= 4 needs only to be checked once.


  • Registered Users Posts: 51 ✭✭nDakota


    @TrueDub
    Oh the way I thought of it, the method would have to be in a separate class. I was going to use it in class University.
    public boolean isQualified(Student lcStudent){
    }
    Except I'd have to change "Student" to "Subject"

    Yeah, like you said. I'm looking for a method that can calculate the totalPoints and be able to use that method in the isQualified method. If that's possible at all?
    But if it's easier to have it in the Main class, I'll definitely do it that way.
    @Seifer Thanks for the advice.


  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,646 Mod ✭✭✭✭TrueDub


    nDakota wrote: »
    @TrueDub
    Oh the way I thought of it, the method would have to be in a separate class. I was going to use it in class University.
    public boolean isQualified(Student lcStudent){
    }
    Except I'd have to change "Student" to "Subject"

    Yeah, like you said. I'm looking for a method that can calculate the totalPoints and be able to use that method in the isQualified method. If that's possible at all?
    But if it's easier to have it in the Main class, I'll definitely do it that way.

    It looks to me like what you need is a Student class. You can then store the student's results in that class, and have the getPoints method there also.

    Then you can implement the isQualified method, but pass in an int instead, consisting of the points required for the relevant course. In the method you compare the student's points to the int parameter and return true if the points are equal to or greater than the parameter, or return false otherwise.

    This will allow you to check a student's eligibility for multiple courses quickly, as all you have to do is call that method repeatedly, passing in the required points threshold.


Advertisement