![]() |
What is wrong with this code?
[code]//***********************************************************************
// xxxxx Project 4-4 11/26/05 // Design and implement a class called PairOfDice, with two six-sided // Die objects. Create a driver class called BoxCars with a main method // that rolls a PairOfDice object 1000 time, counting the number of box // cars (two sixes) that occur. //*********************************************************************** import cs1.Keyboard; import java.util.Random; import java.lang.Math; public class P4_4 { int sides = 6; // Creates the 2 die objects + and rolls them. Die Dice1 = new Die(sides); Die Dice2 = new Die(sides); Dice1.roll(); Dice2.roll(); System.out.println("You rolled a " +die1 +die2); // rolls the dice. public void roll() { DiceRoll = (int) (Math.random()*NUM_SIDES) + 1; } }[code] It keeps saying <identifier> expected on the Dice1.roll(); and the next 2 lines ARGHH. Im new to java and i dont understand what im doing wrong |
im not a java programmer, but your listing the function after the main and with no prototype... i know in C++ this would conflict with the compiler.
EDIT: Hence, <identifier> expected |
You are calling methods in a class. The Dice1.roll(); is being called, yet you have no method called Dice1.roll or Dice2.roll...What exactly are you trying to do with this program?
|
its not obvious what he is trying to do, i think it is. anyway his problem is he has errors lol and wants help.
|
Let's See...
First what is Die? A class you already implemented? .... And as the instructions say....You need a main method to run your class !! You need to build the PairO fDice class and the BoxCars class that will hold the main method! :rolleyes:
:
public class BoxCars { |
It looks like you are having quite a few problems, so where to start first? :)
You have no main method.... DiceRoll has no type associated with it..... You have no real constructor for your class.... die1 and die2 have no types associated with them..... NUM_SIDES is not initialized to anything..... It would be really helpful to see the all of your code, otherwise we are just making assumptions about what you do and do not know how to do. :) |
First of all code tages are used like html tags u have to have a[*] and a [/*] ( "*" being the word code or what ever it is) so then it looks like this
:
it looks a lot better this way. also would you happen to be taking A.P. Computer Science with Mr. Hillestead? If you are then just talk to me tommorow.The reason I ask if you are in that class is because the cs1.Keyboard is something that is commonly used in that course. |
...
Try this on your main class
:
|
That code rolls both dices 1000 times and counts how many times each side appears! Get a clue from it!
|
:
//***********************************************************************Ok thats what i have now. Im so confused. I used your code above, but it only asks for when two 6's are rolled. these are the errors i'm getting: :
cannot resolve symbolIm about to just give up as im completely fried. I dont understand this and its so frustrating. |
| All times are GMT -5. The time now is 9:40 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC