Results 1 to 8 of 8
  1. #1
    jb1991 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Unhappy help with methods!!!!

    I am in a java class and I have figured out everything for what we need to do besides one part, which might just be because I am not understanding so I will show what the questions are (only because I am not sure if they will help to make the question I need help on more clear) and I will put the one I need help on in bold. And then I will show what I have so far just for that part.
    **Hopefully I am approaching getting help on this in the right way, up until this point I have been figuring everything out on my own and have never used a forum for java before! :)

    The methods to be implemented are listed below. Note that using the right case is extremely important.
    a constructor that takes the department and number (in that order) and creates a new instance of a course.
    String toString() that returns a String with the department name, followed by the number, colon, space, crn, dash, and course name. For example, "CS160: 32456-Foundations in Programming"
    get methods:
    String getDepartment(): returns the department as a String
    int getNumber(): returns the number as an int
    String getName(): returns the name as a String
    int getCrn(): returns the number as an int
    int getMaxEnrollment(): returns the number as an int
    int getActualEnrollment(): returns the number as an int
    set methods:
    void setName(String name): sets the course name
    void setCrn(int crn): sets the crn
    void setMaxEnrollment(int n): sets the max enrollment forthe course
    boolean isSpaceAvailable(): returns true if actual enrollment is less than max enrollment, false otherwise
    addStudent(): increments actual enrollment by 1. It is the caller's responsibility to first check if there is space.
    removeStudent(): decrements actual enrollment by 1. It is the method's responsibility to check if there is a student to remove.
    I just do not understand what is supposed to be checked by the method...?

    Here is what I have:

    public int removeStudent()
    {
    int remove;
    if(actualEnrollment > 0)
    {
    remove = actualEnrollment - 1;
    actualEnrollment = remove;
    }
    return actualEnrollment;
    }


    If you need to see more of what I have, just let me know!

    Thanks in advance!!!!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: help with methods!!!!

    Does the method do what is required? Have you tested it? What happens?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    VanGo is offline Member
    Join Date
    Apr 2009
    Posts
    12
    Rep Power
    0

    Default Re: help with methods!!!!

    ? check to make sure there is a least one student in the list ? if there are no students you cannot remove one

  4. #4
    jb1991 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: help with methods!!!!

    I know that the method I have there will "remove student", but I am not sure how to test to make sure the method is checking it opposed to the caller checking it (like in the part about "addStudent")

  5. #5
    jb1991 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: help with methods!!!!

    VanGo..
    that makes sense, I did not even think of that.
    I will try that approach
    Thanks

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: help with methods!!!!

    ow to test to make sure the method is checking
    Add an else clause to the if and have it print out a message saying there are no students left.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    jb1991 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: help with methods!!!!

    Quote Originally Posted by Norm View Post
    Add an else clause to the if and have it print out a message saying there are no students left.
    I got it working, thank you!!

  8. #8
    jb1991 is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: help with methods!!!!

    Quote Originally Posted by VanGo View Post
    ? check to make sure there is a least one student in the list ? if there are no students you cannot remove one
    I got it to work, thank you for clearing that up for me!

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Java Noob, trying to call methods from another methods
    By gabrielpr12 in forum New To Java
    Replies: 8
    Last Post: 11-17-2011, 09:07 PM
  3. Replies: 1
    Last Post: 10-23-2011, 12:37 PM
  4. Replies: 1
    Last Post: 10-05-2011, 12:15 AM
  5. Replies: 4
    Last Post: 04-03-2009, 06:36 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
  •