This is the first time we are making our own classes and I am kind of lost. I have read the chapter like 10 times but the book is too vague.
Basically I have to create a class called Die to represent a Die. It has to have a method called rollDie that generates a number between 1 and 6. I have to have a constructor that initializes the die to 1. I ahve to make a program to test it so I am trying to make a program that calls the class and generates a random number when run ann outputs it. bit it outputs a bunch of random numbers and letters.
here is the class I made:
CODE
/* Problem6
* Brandon Watkins
* 9/23/08
* Die Class
*
* generates random number between 1 and 6 when die is rolled
*/
import java.util.*;
import java.lang.*;
public class Die {
public int Die;
public Die() {
Die = 1; //Constructor initializes die as 1
}
public int rollDie (int rollDie)
{
rollDie = (int) (Math.random() * 6) + 1;
return Die; // generates random number between 1 and 6
}
}
here is the program I have so far:
CODE
/* Problem6
* Brandon Watkins
* 9/23/08
*
*
* generates random number between 1 and 6 when die is rolled
*/
// Import Classes Uncomment as needed
import java.util.*;
import java.lang.*;
//replace ,program name> below with your program's name without the < and >
public class Problem6
{
static Scanner console = new Scanner (System.in);
public static void main(String[] args)
{
//variable declaration
Die result = new Die();
//executable statements
System.out.println("You rolled " + result);
}
}
here is that I output, I want it to say You rolled ( a number between 1 and 6 is printed)
here is what i get:
CODE
You rolled Die@61de33