943,945 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2197
  • Java RSS
Feb 24th, 2005
0

lost on writing a Java class

Expand Post »
I am new to programming and have a project due and am at a total loss. I've been sitting here reading the book for two hours and can not figure my problem out.

Here is my project:
You're helping Danny Ocean with his plot to rob a casino or two in the Las Vegas area. Unlike in the movie, Danny has not already decided which casinos to rob: his personal grudge against their owner was worked out in therapy sessions. Nonetheless, Danny has a standard of living to maintain, and hence will be doing some sophisticated research about the casinos from which he will ultimately choose.

He has brought you into his ring of crime by contracting you to write some software for him which will enable him to track the casinos and some key properties of them. Here's the piece of code you must write for now:

Write a class called Casino which will hold several important pieces of information regarding the casino. It will hold the name of the casino, the name of the owner, the address of the casino, the level of difficulty of getting into the vault, and the average amount of cash usually kept in the vault.

The level of difficulty should be stored as an enumerated type with the following values as its fields:

impossible, veryDifficult, difficult, easy, veryEasy

You will need a constructor, methods to get and set each variable, and a method called checkOwner which will accept a string as a parameter and return a boolean value depending on whether the owner's last name begins with the string passed in as a parameter.

You will write a driver to test your class, but you will only turn in the class to me.

You'll have to store the first name and last name separately, but that should not be apparent to the client upon calling getName(). You will also need to make your checkOwner() method non-case sensitive, so you should uppercase or lowercase all strings to be compared. Read about toUpperCase() and toLowerCase() in the String class API.

You do not need to write a setName() method. That will come later.

Here's a complete list of methods you'll need along with the types and orders of their parameters. On the constructor, you do not need to name your parameters identically to mine, but you do need to put them in the same order. NAME YOUR METHODS EXACTLY AS I HAVE OUTLINED BELOW.

Casino(String casinoName, String ownerFirstName, String ownerLastname, String address, DifficultyLevel d, int averageCash)

getCasinoName()
setCasinoName(String)
getOwnerName()
getAddress()
setAddress(String)
getAveragecash()
setAverageCash(int)
checkOwner(String)
toString()

I basically do not have anything done. I am mainly trying to figure out how to start and how to do these get and sets.

ANY help would be greatly appreciated!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dools is offline Offline
1 posts
since Feb 2005
Feb 24th, 2005
0

Re: lost on writing a Java class

you need to create a class with properties that you pass to your constructor.
and you simply write get, set methods for them.... an example :
Java Syntax (Toggle Plain Text)
  1. public class book {
  2. //properties
  3. String name;
  4. String Author;
  5. int pages;
  6. //here is the constructor;
  7. public book(String name, String Author, int pages) {
  8. this.name= name;
  9. this.Author= Author;
  10. this.pages= pages;
  11. }
  12. //getters, setters...
  13. public String getName() {
  14. return name;
  15. }
  16. public String getAuthor() {
  17. return Author;
  18. }
  19. public int getPages() {
  20. return pages;
  21. }
  22.  
  23. public void setName(String newName) {
  24. this.name =newName;
  25. }
  26. public void setAuthor(String newAuthor) {
  27. this.Author =newAuthor;
  28. }
  29. public void setPages(int newPages) {
  30. this.pages =newPages;
  31. }
  32.  
  33. }

only difference in your code will be in checkOwner(String) which you need to make a comparation and getOwnerName() , which you need to join to Strings...
Reputation Points: 25
Solved Threads: 11
Junior Poster
tonakai is offline Offline
121 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: JTextPane
Next Thread in Java Forum Timeline: getting rid of console window using a gui





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC