aspose file tools*
The moose likes Beginning Java and the fly likes Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classes" Watch "Classes" New topic
Author

Classes

jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
This is the requirements for the Student class I have to create. I created all of it to what I think is right by i am running it to some problems in storing and in my
setNames(iNames);
setMajors(iMajors);
setCredits(iCredits);
Any help or suggestions in stuff that I missed or that does not look right.
The Student class
Within the App.java source file and after the closing brace of the App class, define an instantiable Student class. The class must contain:
�Instance variables for holding the student's name (a String), major (a StringBuffer), and credits earned (an int). All instance variables must be declared private.
�A public class constant named SENIOR with an int value of 90. This will be used to determine whether a student is a senior.
�A single constructor that accepts values for all three instance variables. It should call the "set" methods (described below) to edit and store the initial values it receives.
�Instance methods to "set" and "get" the value of each instance variable. Each "get" method should simply return the value of its corresponding variable.
The "set" method that stores the student's name must receive a String and store it if it isn't empty. Nothing must be returned to the caller.
The "set" method that stores the student's major must receive a StringBuffer and store it if the value of its string is "CIS", "MGT", "MKT", "ACT", or "none". Otherwise, nothing should be stored. The method must return a boolean to indicate whether the data it received was valid.
The "set" method that stores the credits earned must receive an int and store it if the value is greater than or equal to zero. Otherwise, nothing should be stored. The method must return a boolean to indicate whether the data it received was valid.
�An instance method named isSenior that accepts no parameters and returns a boolean that indicates if the student is a senior.

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It looks like you have a really good start with the assignment. Can you be more specific about the exact troubles you are having with those three methods?


Java API Documentation
The Java Tutorial
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

In most cases people don't call set methods from within their constructors. They just set the instance variable directly.
In your case your set methods are a little more compilicated. And you don't check the booleans which are being returned.
So, ... what is your problem?


Please ignore post, I have no idea what I am talking about.
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
At this line

i am getting this error
'class' or 'interface' expected at line 31
and at this line

and this error
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
Sorry the error is
'class' or 'interface' expected at line 51
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

First off you have 2 methods called setMajors, why confuse yourself that way?
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Your curley's are mismatched. That method, and everything below it is outside of the class.
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
What do you suggest i have two if else statements and i thought it would work that way.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12

Notice the additional curly brace in the else block?
[ April 14, 2003: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
jon ladd
Ranch Hand

Joined: Feb 11, 2003
Posts: 53
Can some tell me for sure if i have met all the requirements. i think i have.
Donald R. Cossitt
buckaroo
Ranch Hand

Joined: Jan 31, 2003
Posts: 401

First off you have 2 methods called setMajors, why confuse yourself that way?

I am going to run the risk of sounding like a nitpicker but methods starting with 'set' implies 'void'. Whereas 'has' or 'is' implies true or false? Whereas 'get' or 'do' or ... implies some other return?
See �6.8.3 Method Names et seq.
doco
[ April 15, 2003: Message edited by: Donald R. Cossitt ]

doco
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

methods starting with 'set' implies 'void'. Whereas 'has' or 'is' implies true or false?

I agree.
subhit chauhan
Ranch Hand

Joined: Jun 20, 2002
Posts: 40
wrong curly braces...
your methods are not inside any class...
and methods naming convention is wrong
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Classes