aspose file tools*
The moose likes Beginning Java and the fly likes Method problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method problem" Watch "Method problem" New topic
Author

Method problem

Harold Pint
Greenhorn

Joined: Mar 25, 2010
Posts: 1
Hi all,

I'm new to Java, learning it for my Computing course at university.

For a project over Easter I must make a simple game on the concept of rock, paper, scissors.
Note the game is nothing graphical yet, just command line stuff.

The first activity is to create a class to make the base units. (This game is using land, sea and air instead of rock, paper and scissors.)
I have done this, however I need methods to make the units attack each other.

I need two methods, one to attack, and another to calculate the damage. The attack method is called and uses the damage method to deal damage to the other unit.

How can I instruct the attack method to use the damage method?


Here is my code:



and the main method to test this:



The attack and damage methods are currently incomplete. If I comment them out and run the program, it returns this result:
Base Unit (100/100)
Gary (75/100) false



So how can I code this problem? I remember one of my classmates working on it, and having something like


Is this on the right lines?

I hope you can help me.

Thanks in advance.
Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
First of all, I don't think you will find anyone to do your homework for you on this or any other site.

With that in mind, all you have done, providing that everything compiles okay, is to output the data
represented by your first reference to the Unit object, and the second reference. Also, our not passing anything into the dead
method so it is really not doing anything useful.

status should be a class member like boolean STATUS.

What you might think about doing is to give paper, rock, and scissors a value to compare against one another.
Then you would have something to compare against.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40063
    
  28
Welcome to JavaRanch

What is the d parameter in the damage() method? You appear not to be using it; why not?

I think you need to get a pencil and paper and write down what each method is supposed to do, and how the class should be constituted. In the attack method, you need to invoke the damage method on your opponent's object reference.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method problem