• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classes

 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry the error is
'class' or 'interface' expected at line 51
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off you have 2 methods called setMajors, why confuse yourself that way?
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your curley's are mismatched. That method, and everything below it is outside of the class.
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you suggest i have two if else statements and i thought it would work that way.
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Notice the additional curly brace in the else block?
[ April 14, 2003: Message edited by: Marilyn de Queiroz ]
 
jon ladd
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some tell me for sure if i have met all the requirements. i think i have.
 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
methods starting with 'set' implies 'void'. Whereas 'has' or 'is' implies true or false?

I agree.
 
subhit chauhan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wrong curly braces...
your methods are not inside any class...
and methods naming convention is wrong
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic