Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hwk3_kristian_simovski;
- import java.util.Random;
- public class Coin {
- private int value;
- private String sideUp;
- private Random rnd;
- //constructor method
- public Coin(){
- rnd = new Random();
- flipCoin();
- }
- //method to flip the coin
- public void flipCoin(){
- value = rnd.nextInt(2);
- if (value == 1)
- {
- sideUp = "Heads" ;
- }
- else
- {
- sideUp = "Tails" ;
- }
- }
- //returns the value to the side that will be displayed
- public String getFace(){
- return sideUp;
- }
- //returns s string containing the value and side facing up
- public String toString(){
- return "Value: " + value + ",sideUp: " + sideUp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement