Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Instantiating a class?

$
0
0
Is such a thing even possible? I'm supposed to implement GameInterface and and have my RouletteGame class have private instance variables for a RouletteWheel, and RouletteTable.(These are other classesin separate file) And then have a constructor that instatiates the RouletteTable and RouletteWheel. The best I could come up with was:
public class RouletteGame implements GameInterface{
		private RouletteTable table;
		private RouletteWheel wheel;
		
		public RouletteGame(){
			table.initializeBet();
			wheel.setTheNumber();
		}
		
	}



Set number looks like:
public static final int setTheNumber(){
    	
    	chosen = ((int)(Math.random() * (36 - 0) + 1)); 
    	System.out.println("Chosen # = "+ chosen);
    	return chosen;
    }


InitializeBet looks like:
public void initializeBet(){
		odd = new RouletteSpot(1);
		even = new RouletteSpot(1);
		red = new RouletteSpot(1);
		black = new RouletteSpot(1);
		firstThird = new RouletteSpot(2);
		secondThird = new RouletteSpot(2);
		thirdThird = new RouletteSpot(2);
		
		for(int i = 0; i < 37; i++){
			spotArray[i] = new RouletteSpot(35);
	}



-But I know that can't be right because then I have to override the initGame method(its an abstract method inside of GameInterface) by calling RouletteTables initialize method. But since I am mistakenly doing it above, that wouldn't make sense. Could someone help me figure this out?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>