Nope, this is quite good. The only thing your missing is actually doing something with the pair of die (you can't print it out quite like that either).
In your main method, you simply need a dice.roll(); call. That's it, that will roll your die.
Simplify your code in your paired dice class - you don't need to track the totals ever:
public class PairOfDice
Die die1 = new Die();
Die die2 = new Die();
//Method to roll both dice and return the combined result.
public int roll()
return (die1.roll() + die2.roll());
//Method to returns the current combined dice total.
public int getTotal()
return die1.getFaceValue() + die2.getFaceValue();
//Method to returns the current value of the first die.
public int getDie1()
//Method to returns the current value of the second die.
public int getDie2()
As you can see above, try to chain as many things together as you can instead of tracking things individually - centralization is a key point to OOP; you only want to manage this data at one level if possible.
Now when you call dice.roll() in main, it will return an integer with the new die totals which you can capture and print out if you like. If you want to use System.out.println or any type of string evaluation on a class, you need to override the toString method on object in order to have it change the looks (otherwise you tend to get just a simple identifier for the object [myobject@234a33 for example]).
For a bonus tip, always override the toString. Always. Write it in a way that makes sense to display (I'll use the stringBuffer class to write, though standard appending works just fine as well):
public String toString()
StringBuffer sResult = new StringBuffer("Die[");
sResult.append("faceValue=" + this.getFaceValue());
// And I'll add one in pair as well:
public String toString()
StringBuffer sResult = new StringBuffer("PairOfDice[");
sResult.append("die1=" + this.die1.toString()); // .toString should be optional, just a habit I've gotten into much like using this. when not necessary.
sResult.append(", die2=" + this.die2.toString());
I suggest this since now you can use a System.out.println(dice), and it will show the contents and chain it to the die1 and die2 toString calls to display something much like
. This is exceedingly helpful with debugging. If you have a particular format you'd like to output, I'd recommend not using the toString to do so if you can avoid it, and choosing instead to call a particular method to do the formatting.
These are just tips to help you out, in particular the pairofdice class doesn't actually need to change as it appears to be functional to me. I assumed that at this level you are not dealing quite with arrays or exceptions or anything like that (in which case I'd suggest creating a Dice class instead of pairOfdice, and pushing as many die as you like onto it).
Good luck, post back with any other questions you may have. Also, in the future use the [code][/code] or [php][/php] tags instead of [icode][/icode] in order to preserve the format of your code.