Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Confusion about class members  RSS feed

 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,this is a piece of my problem
Design a student class that has a class status (freshman, sophomore, junior, or senior). Define the status as a constant.
Is this code true for this piece of the problem?
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks right to me...there are other ways, but that is the most basic...based on what you said, they don't need to be private, unless in certain circumstances (the need for security, etc)
Hope I helped,
cc11rocks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use an enum rather than int values?

Also, convention dictates all uppercase for constants: FRESHMAN, for example.
 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use an enum rather than int values?

thanks for your help, but can you tell me how can i define enum?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


(It could also be declared in its own Java file if you wanted it to be divorced from Student.)

To use in Student:


To use outside Student:
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Notice that the problem statement said "define the class status as a constant". The instructor/textbook/whatever may not accept an enum as an answer. I'm not saying that they should not, only that they might not.

rc
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is an enum not a constant?
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just mean that the instructor may have had in mind defining integer constants exactly how the OP had them. Some instructors are not that flexible about other ways of doing things, esp. not with newer features they may not know very well.

rc
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!