Results 1 to 8 of 8
Thread: help with methods!!!!
- 04-24-2012, 03:46 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
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.
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!!!!
- 04-24-2012, 04:07 AM #2
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.
- 04-24-2012, 04:08 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 12
- Rep Power
- 0
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
- 04-24-2012, 04:09 AM #4
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
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")
- 04-24-2012, 04:11 AM #5
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
Re: help with methods!!!!
VanGo..
that makes sense, I did not even think of that.
I will try that approach
Thanks
- 04-24-2012, 04:13 AM #6
Re: help with methods!!!!
ow to test to make sure the method is checkingIf you don't understand my response, don't ignore it, ask a question.
- 04-24-2012, 04:15 AM #7
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
- 04-24-2012, 04:16 AM #8
Member
- Join Date
- Apr 2012
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-17-2012, 12:00 AM -
Java Noob, trying to call methods from another methods
By gabrielpr12 in forum New To JavaReplies: 8Last Post: 11-17-2011, 10:07 PM -
difference between static methods and instantce methods?
By venkatch in forum New To JavaReplies: 1Last Post: 10-23-2011, 01:37 PM -
Incorporating If-Else into Methods + Private Helper Methods?
By 5minutes in forum New To JavaReplies: 1Last Post: 10-05-2011, 01:15 AM -
How to get methods to see variables in other methods
By ejs7597 in forum New To JavaReplies: 4Last Post: 04-03-2009, 07:36 AM
Bookmarks