Categories

JAVA DATEBASE
Technology Network Community
Oracle Database
Fusion Middleware
Development Tools
Java
Desktop
Server & Storage Systems
Enterprise Management
Berkeley DB Family
Cloud Computing
Big Data
Business Intelligence
Architecture
Migration and Modernization
E-Business Suite
Siebel
PeopleSoft Enterprise
JD Edwards World
Industries
JD Edwards EnterpriseOne
User Productivity Kit Pro (UPK) and Tutor
Governance, Risk & Compliance (GRC)
Master Data Management (MDM)
Oracle CRM On Demand
On Demand: SaaS and Managed Applications
AutoVue Enterprise Visualization
Primavera
ATG
Agile PLM
Endeca Experience Management
Fusion Applications
Archived Forums

 



Tags

New To Java


die simulator


I am doing a die simulation with the requirements; Instance Variables: 	sides ? holds the integer number of sides on the die  	faceValue ? holds the integer from 1 to sides that is currently showing face-up on the die   Class Constructor-	 Initializes the value of faceValue to 1 and the value of sides to 6  Methods: int getSides() This method simply returns the integer number of sides on the die.  int getFaceValue( ) This method simply returns the integer faceValue showing on the die.  void setSides(__?__) This method takes as a parameter, the integer number of sides the die should have, and sets the instance variable sides to this value.  In addition to providing the body of this method, you will have to complete the method signature which indicates the data type and name of the method parameter used inside the body of the method.  void rollDie( ) This method rolls the Die, thus setting the faceValue of the Die.  If anyone could give me any tips on how to get this started, i would appriciate it

class DieSimulation {     // instance variables       // constructor(s)       // method(s) }  Just fill in the blanks.

It is quite straightforward. The requirements tell you exactly how to write the only class needed. The only method that needs more than one line of code is rollDie(), in which you'll need to pick a random value -- for this you can use java.util.Random.  Add also a main() method to the class to test your code.

hmm, was thinking along the lines of public class DieSimulator {   public static void main(String[] args) {     System.out.println("Aaaaaaaarrrrrggggghhh");   } }   "Maybe he was dictating". Lord Bedevere.

import java.util.Random; class die{   private int side,faceValue;   die() {         side = 6;         faceValue=1;   }   int getFaceValue(){          return faceValue;   }   void setSides(int side){         this.side=side;  }  void roll(){         faceValue=(int)(Math.random()*(side+1));  } } class DieTry{   public static void main(String args[]){            die t=new die();            t.setSides(5);            for(int i=0;i<5;i++){                 t.roll();                   System.out.println("Face Value..."+t.getFaceValue());           }   } }       Hope this would help you...

Hope this would help you...  Doing the OP's homework won't help him learn Java at all and may let him in the bad habit of cheating. Furthermore your code has errors.  Message was edited by: java_knight

hmm, was thinking along the lines of public class DieSimulator {   public static void main(String[] args) {   System.out.println("Aaaaaaaarrrrrggggghhh"); } }   "Maybe he was dictating". Lord Bedevere.  A normal die has 6 sides.  Your program only works if the number is three: "then shalt thou count to three, no more, no less. Three shall be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out. "

There are chances that the roll method in above class Die will return 0 for face value .. coz the radom number returned is between 0.0 and 1.0 so it can even  return 0.01 which will result in a facevalue of 0   so its better to use ,   void roll(){         faceValue=(int)(Math.random()*side)  + 1;  }

There are chances that the roll method in above class Die will return 0 for face value .. coz the radom number returned is between 0.0 and 1.0 so it can even  return 0.01 which will result in a facevalue of 0   so its better to use ,   void roll(){         faceValue=(int)(Math.random()*side)  + 1;  java.util.Random would be better.

There are chances that the roll method in above class Die will return 0 for face value .. coz the radom number returned is between 0.0 and 1.0 so it can even  return 0.01 which will result in a facevalue of 0   so its better to use ,   void roll(){         faceValue=(int)(Math.random()*side)  + 1;   java.util.Random would be better.  Just wondering, whats so good about the util.Random ?

java.util.Random would be better.  Just wondering, whats so good about the util.Random ?  It's chock full of methody goodness!

java.util.Random would be better.  Just wondering, whats so good about the util.Random ?  It's chock full of methody goodness!  loving it

Just wondering, whats so good about the util.Random ?  Math.random delegates to util.Random.  util.Random has methods for some common operations (e.g., a random int between 0 and N).  util.Random gives better distributions than a naive multiplication of Math.random's results. (Don't ask me why--I don't know bollocks about the theory and don't remember enough about the article to give you a link.)


Related Links

consequtive sequence of positive integers = target sum, must build algoryth
Need help (don't know enough Java to continue my program)
SpringLayout button icon
swing components positioning
Can't run HelloWorld!
StringBuffers??
J2SE SDK
I need a jprogress bar
Console -&gt; JTextArea
No getter method available for property address for bean under name org.apa
Should I install a private JRE with my application.
Reading an int from a particular location in a file
Creating A Website
Get a list of files in a folder
putting java Query Resultset data into a .NET like data table
java calculator