ok so i got a java assignment in class and i have no clue where to start or how, my instructions are:
Create a die class that represents one die (sigular of dice) with faces showing values between 1 and the number of faces on the die.
a. defults to a six sided die. intial face value is 1
b.explicitly sets the size of the die defults to a size of six if the parameter is invalild intital face value is 1 .
c. rolls the die and returns the result
d.returns the current die value
Anyways i just wanted to ask if i could please help me out here, i really need it becuase i dont want to fail this class and i really am trying!maybe if someone will i would really apricate if someone would teach me some stuff as far as maybe tutoring?
idk, i just really need help with this asignment please!
Help with java please!!!?
import java.util.*;
public class Die {
private int size;
private int value;
public Die() {
size = 6;
value = 1;
}
public Die(int newSize) {
if(newSize%26lt;2)
size = 6;
else
size = newSize;
value = 1;
}
public int roll() {
Random rand = new Random();
return rand.nextInt(size)+1;
}
public int getValue() {
return value;
}
public int getSize() {
return size;
}
public static void main(String[] args) {
Die die1 = new Die();
Die die2 = new Die(10);
for(int i=0; i%26lt;20; i++) {
System.out.println("First die has "+die1.getSize()+" sides and rolled "+die1.roll());
System.out.println("Second die has "+die2.getSize()+" sides and rolled "+die2.roll());
}
}
}
---------------------------------
Notes: the question wasn't very much clear where you mentioned "explicitly sets the size of the die defults to a size of six if the parameter is invalild" .
What is invalid ? above I assumed invalid to be a size less than 2.
Important : I don't know if you are asked to submit a main method too BUT you can safely delete "public static void main(String[] args)" method. the main method is for testing only.
By the way, I dont know how much you are learning in this class but I tried to keep it simple and not use anything advanced (even though the assignment is simple)
good luck
buy flowers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment