# how to use equals method in the Die class

Page 1 of 1

## 9 Replies - 534 Views - Last Post: 13 October 2011 - 07:51 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=251124&amp;s=4ca552dcef7d9126d7c43a3f64fafbd1&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 remo123

Reputation: 0
• Posts: 6
• Joined: 13-October 11

# how to use equals method in the Die class

Posted 13 October 2011 - 06:52 AM

how to use equals method in Die class
Is This A Good Question/Topic? 0

## Replies To: how to use equals method in the Die class

### #2 Fuzzyness

• Comp Sci Student

Reputation: 669
• Posts: 2,438
• Joined: 06-March 09

## Re: how to use equals method in the Die class

Posted 13 October 2011 - 07:03 AM

Then list any errors that you are getting or what it is doing that you don't want it to do.

### #3 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11391
• Posts: 42,920
• Joined: 27-December 08

## Re: how to use equals method in the Die class

Posted 13 October 2011 - 07:04 AM

This is how you invoke the equals() method.
```if(obj.equals(otherObj)){
//code
}

```

You can also override or overload it when you create a class.
```class Foo{

public boolean equals(Foo other){/*code*/}

//override
public boolean equals(Object other){/*code*/}

}

```

### #4 remo123

Reputation: 0
• Posts: 6
• Joined: 13-October 11

## Re: how to use equals method in the Die class

Posted 13 October 2011 - 07:20 AM

i need to use equals method in dice game i.e in Die class ,,pls suggest me some methods

### #5 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11391
• Posts: 42,920
• Joined: 27-December 08

## Re: how to use equals method in the Die class

Posted 13 October 2011 - 07:21 AM

Your question is ambiguous. I demonstrated usage of the equals() method. What purpose are you trying to achieve? What have you tried? We don't have enough information to help you.

### #6 remo123

Reputation: 0
• Posts: 6
• Joined: 13-October 11

## Re: how to use equals method in the Die class

Posted 13 October 2011 - 07:23 AM

public class Die
{
private int facevalue;
private final int Max=6;
private Random dieGen; // generator

public Die()
{
facevalue = 1;
dieGen = new Random();
}

//Math.random creates random integers from 1 - 6
public void roll()
{
facevalue = dieGen.nextInt(Max) + 1;
}

public void setFaceValue(int value)
{
facevalue=value;
}
public void getFaceValue()
{
return facevalue;
}
public String toString()
{
String result="you rolled " +facevalue;
return result;
}
}

### #7 Fuzzyness

• Comp Sci Student

Reputation: 669
• Posts: 2,438
• Joined: 06-March 09

## Re: how to use equals method in the Die class

Posted 13 October 2011 - 07:25 AM

As mac said we do not have enough information.

I am assuming Die is a single in a pair of dice and you are not talking about Motherboard components. Which means you should probably compare the values that the Die show.

```if(die1.getValue() > die2.getValue())
System.out.println("Die 1 has the greater value, thus winning this round!");
else System.out.println("Died 2 has the greater value, thus winning this round!");

```

Edit - As I said, except change the getValue() method to your getFaceValue();

This post has been edited by Fuzzyness: 13 October 2011 - 07:26 AM

### #8 remo123

Reputation: 0
• Posts: 6
• Joined: 13-October 11

## Re: how to use equals method in the Die class

Posted 13 October 2011 - 07:25 AM

how can i insert equal method in my code

### #9 Fuzzyness

• Comp Sci Student

Reputation: 669
• Posts: 2,438
• Joined: 06-March 09

## Re: how to use equals method in the Die class

Posted 13 October 2011 - 07:33 AM

Put the equals method in your Die class, have it take an object, cast the object as a Die, then call the getFaceValue() and compare them how need be.

### #10 Dogstopper

Reputation: 2950
• Posts: 11,217
• Joined: 15-July 08

## Re: how to use equals method in the Die class

Posted 13 October 2011 - 07:51 AM

You know what remo123? You aren't working on this at all. I have the very distinct feeling that we are literally DOING your homework for you. You simply want a solution and move on without learning. There is enough information in this post for you to be able to figure out what you need. Please do not be a begger.

Topic Closed.