Click here to Skip to main content
15,888,320 members
Home / Discussions / Java
   

Java

 
AnswerRe: Javascript File upload Pin
42774807-Feb-10 18:06
42774807-Feb-10 18:06 
AnswerRe: Javascript File upload Pin
Richard MacCutchan7-Feb-10 22:31
mveRichard MacCutchan7-Feb-10 22:31 
JokeRe: Javascript File upload Pin
42774808-Feb-10 0:21
42774808-Feb-10 0:21 
GeneralRe: Javascript File upload Pin
Richard MacCutchan8-Feb-10 0:35
mveRichard MacCutchan8-Feb-10 0:35 
GeneralRe: Javascript File upload Pin
42774808-Feb-10 0:38
42774808-Feb-10 0:38 
QuestionPhyton to Java Pin
BombayGuy5-Feb-10 12:32
BombayGuy5-Feb-10 12:32 
AnswerRe: Phyton to Java Pin
42774805-Feb-10 20:32
42774805-Feb-10 20:32 
QuestionSlot Machine Java Help [modified] Pin
bmnot4-Feb-10 23:48
bmnot4-Feb-10 23:48 
I have to create a Slot Machine in java for college and am having problems with the last bits of it.

It contains 3 classes, the main slotMachine class(which contains the main logic for the game, calling on the other 2 classes), a Column Class and a slot Class.

here is the code for each:

slotMachine - (Very incomplete - last thing to do!)
import java.io.IOException;

public class slotMachine
{

	public static void main(String[] args) throws NumberFormatException, IOException
	{
		int initialBalance = 10;
		Stream in = new Stream(System.in);
		
		System.out.println("*****WELCOME TO MY SLOT MACHINE*****");
		System.out.println("Your initial balance is: " + initialBalance + " credits");
		System.out.println("Please enter an amount to bet: ");
		int betAmount = in.readInt();
		
	}

}

Column -

import java.util.Random;

public class Column
{
	int faceInt; // 0 = apple, 1 = orange, 2 = pear
	
	public void newFace()
	{
		Random newFace = new Random();	
		faceInt  = newFace.nextInt(3);
	}
	
	public String toString()
	{
		switch(faceInt)
		{
			case 0:
				return ("|APPLE|");
				
			case 1:
				return ("|ORANGE|");
			
			case 2:
				return ("|PEAR|");
		
		}
		
		return null;
	}
	
	
}

Slot -

public class Slot
{
	Column column1, column2, column3;
	
	
	public Column pullHandle()
	{
		column1.newFace();
		column2.newFace();
		column3.newFace();
		
		return column1;
			
	}
	
	public boolean fullHouse()
	{
		if(column1.equals(column2) && column2.equals(column3))
		{
			return true;
		}
		
		else
		{
			return false;
		}
		
	}
	
	public boolean halfHouse()
	{
		if(column1.equals(column2) || column2.equals(column3) || column1.equals(column3))
		{
			return true;
		}
		
		else
		{
			return false;
		}
	}
	
	
}


I am trying to call the pullHandle method (located in the Slot class) in the slotMachine class, but don't know how! When I put Slot.pullHandle(); in the main class, it doesn't work, giving me the error of can't reference a static type, from a non static source (or something like that), so I change it to static, then when I run it I get an error saying:

Exception in thread "main" java.lang.NullPointerException
at Slot.pullHandle(Slot.java:8)
at slotMachine.main(slotMachine.java:18)

Also, in the Slot class, for the pullHandle class I want to return the 3 columns, but keep getting a code unreachable error.


This is stressing me out! Help me please!
modified on Monday, February 8, 2010 5:40 PM

AnswerRe: Slot Machine Java Help Pin
Richard MacCutchan5-Feb-10 1:00
mveRichard MacCutchan5-Feb-10 1:00 
GeneralRe: Slot Machine Java Help Pin
bmnot8-Feb-10 11:21
bmnot8-Feb-10 11:21 
GeneralRe: Slot Machine Java Help Pin
Richard MacCutchan8-Feb-10 11:36
mveRichard MacCutchan8-Feb-10 11:36 
GeneralRe: Slot Machine Java Help Pin
bmnot8-Feb-10 11:43
bmnot8-Feb-10 11:43 
GeneralRe: Slot Machine Java Help Pin
Richard MacCutchan8-Feb-10 21:16
mveRichard MacCutchan8-Feb-10 21:16 
GeneralRe: Slot Machine Java Help Pin
TorstenH.8-Feb-10 22:39
TorstenH.8-Feb-10 22:39 
Questionhow to change the center of rotation? Pin
002comp4-Feb-10 21:52
002comp4-Feb-10 21:52 
AnswerRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
002comp7-Feb-10 22:18
002comp7-Feb-10 22:18 
GeneralRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
Richard MacCutchan8-Feb-10 0:38
mveRichard MacCutchan8-Feb-10 0:38 
GeneralRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
42774808-Feb-10 0:40
42774808-Feb-10 0:40 
GeneralRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
002comp8-Feb-10 0:43
002comp8-Feb-10 0:43 
GeneralRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
42774808-Feb-10 1:10
42774808-Feb-10 1:10 
GeneralRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
002comp8-Feb-10 0:44
002comp8-Feb-10 0:44 
GeneralRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
Richard MacCutchan8-Feb-10 1:38
mveRichard MacCutchan8-Feb-10 1:38 
GeneralRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
002comp8-Feb-10 17:39
002comp8-Feb-10 17:39 
GeneralRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
Richard MacCutchan8-Feb-10 21:19
mveRichard MacCutchan8-Feb-10 21:19 
GeneralRe: how to change the center of rotation?(Solved) Next Ques:convert Local to World cordinates. Pin
002comp8-Feb-10 21:33
002comp8-Feb-10 21:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.