Java programming problem.

Discussion in 'Software' started by xscarsofdesirex, Feb 27, 2005.

  1. xscarsofdesirex

    xscarsofdesirex Private E-2

    Probably a very simple program for Java, but I am completely stumped.
    Any help in coding (even hints) for this would be GREATLY appreciated.
    If you would like to contact me directly, my AIM is XscarsofdesireX.


    Write a class called Card where each object represents a card. The class should have three instance variables.
    int myNum (stores a value 1 to 52)
    String mySuit (suit of the card- to be determined by myNum)
    String myValue (value of the card -1,....10,Jack, Queen, King, Ace)
    (use integer division for mySuit and % for myValue)

    The class should have a setValue() and setSuit(). They should be called in the constructor.

    Then write a class called DeckOfCards that holds 52 objects of type cards. Write methods that will assign each card a different number 1 to 52, will shuffle the deck, will deal a card, and tell how many cards are left.

    Create a driver that will shuffle the deck, then pring out as many cards as the user wants dealt from the top of the deck.
     
  2. QuickSilver

    QuickSilver Corporal

    This is a typical first jump into the whacky world of Object Oriented development. A lot of what you require is pretty straight forwards.

    What in particular are you having trouble with? What parts of the development are you struggling with. I don't think 2 many people will put the full code out for you, and if they did you possibly wouldn't learn as much from the exercise.

    So by all means post pieces of code you have which are not working or are misbehaving and ask us about specific things you don't understand to do with OO and Java issues etc.

    To summarise what you need :
    An Object with 3 private variables.
    A constructor method.
    Set and Get methods for each variable.

    It is generally considered good practice to have variables in an object as private. There are exceptions to when this is a good idea. The basic idea behind this is that you make the variable private - this means that only that object can see it and nothing outside of that object can. You then provide public methods for other objects to change these. From outside of your object the only way something can see or change these variables is through an interface you define. These methods are typically called get and set methods.

    So what I suggest you do is focus your initial energies on is creating this object with the variables and the get/set methods. Write a simple object to create an instance of the object, with the constructor and use your get and set methods to try accessing and changing your methods and seeing these changes.

    Remember developing anything is a gradual process. Look at breaking your tasks into smaller managable goals and then do each one.

    Good luck and we all look forwards to hearing how you get on.
     
  3. QuickSilver

    QuickSilver Corporal

    I know the above isn't everything you need but ti is enough to get started on. Once you've done that you will have the building blocks for beginning to tackle the rest of your challenge.

    Cheers
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds