Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Basic OOP having trouble determining how to handle methods

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Thanked 0 Times in 0 Posts

    Default Basic OOP having trouble determining how to handle methods

    Hey. Thanks for taking a look,

    I'm working on a class assignment that creates a "Space Merchant" game where you buy and sell commodities and travel to complete missions. My part of the assignment is broken up to six classes (Commodity, Ship, Player, Location, Mission and SpaceMerchant) where I am given the instance methods, I just have to fill them out based on their description. Also included in the program are four completed classes (World, Pair, Action, and UserInterface). Since there is so much involved, I've decided to not post my code directly on here but make a rar file including my progress on the six classes, the JAR file including the four given classes, and the text based world.

    It is located here: SpaceMerchant.rar (Mediafire link that takes you to the download, not a direct download)

    I'd like to think I'm pretty far in the assignment but still have some lingering issues
    In the Player class, I am unsure of how to complete getMission and setMission. I've noticed that the return variable for one is the given parameter for the other. I'm unsure if they have a relationship or if they should be developed completely different.

    In the Mission class, I have the same situation with isComplete and setComplete.

    Finally, I'm stuck on the SpaceMerchant class. This is the class that is responsible for putting everything in motion including loading the world. I heard my lecturer explain to another student that a switch or if/else if tree is needed (that's why you see the beginning of one in my code). Beyond that, I have no idea and I'm hoping for a little direction.

    I realize this is a lot to ask, and I'm very appreciative of those willing to give it a shot. I'm really stuck and could use any advice or even a point in the right direction.
    Thank you

  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Faversham, Kent, UK
    My Mood
    Thanked 58 Times in 54 Posts

    Default Re: Basic OOP having trouble determining how to handle methods

    I doubt many will download a rar to look at some code, but getMission and setMission presumably deal with a mission, so you'd expect setMission to take a Mission argument and getMission to return a Mission. Usually, in setMission, the Mission would be stored in a class variable, and getMission would return that variable. Similarly for isComplete and setComplete. The Java convention for methods returning a boolean value is to call them isXxxxx rather than getXxxxx because it makes the code read better. But they're usually handled similarly - setComplete sets a boolean class variable and isComplete returns that variable. Of course, the setXxxx methods might do some other stuff related to setting the relevant variable, but more often than not, they just set the class variable.

    As for SpaceMerchant, hoping for a little direction is a bit vague. You need to explain exactly what the bit you're having trouble with is supposed to do, and why you're having trouble with it. Posting some relevant code wouldn't hurt either.

Similar Threads

  1. Try : handle an exception by yourself.
    By try in forum Member Introductions
    Replies: 1
    Last Post: July 12th, 2011, 10:37 AM
  2. Determining Linear Approximations
    By ddunlop07 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 13th, 2011, 12:12 AM
  3. how to handle many more exceptions
    By shailaja in forum Member Introductions
    Replies: 1
    Last Post: December 27th, 2010, 01:02 AM
  4. El Gamal signature -Handle big integer
    By miotvsingtel in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 9th, 2010, 12:05 PM
  5. How to handle quadratic roots that don't exist?
    By kairojya in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 28th, 2009, 12:21 PM