Calling a variable from a different java class
Hi:
I have created a class and inside the class a setter method. This setter method doesnt seem to recognize the variables within the constructor method.
Here is the code of the main program:
Code:
import java.util.*;
class Roulette
{
static int [] moneyLeft = new int [50];
static String [] players = new String [50];
public static void main (String [] args)
{
System.out.println("\n WELCOME TO ROULETTE");
System.out.println("---------------------------------------------------------------");
System.out.println("First type the name of the players.");
System.out.println("When you are done entering their names, enter \"no\" to continue.\n");
Scanner keyboard = new Scanner (System.in);
for(int i=1; i< 50; i++)
{
System.out.println("What is the name of player #" + i + "?");
String s = keyboard.next();
if(s.equalsIgnoreCase("no"))
{
i = 50;
}
else
{
players[i] = s;
System.out.println("How much money does " + players[i] + " want to start off with?");
moneyLeft[i] = keyboard.nextInt();
}
}
int h =1;
Bet actuaBet;
System.out.println("How much would you like to bet?");
int moneySpent = keyboard.nextInt();
//moneyLeft[h] = moneyLeft[h] - moneySpent;
System.out.println("What Type of bet would you like to do?");
String response = keyboard.next();
if (response.equalsIgnoreCase("N"))
{
System.out.println("What number do you choose?");
int choice = keyboard.nextInt();
Bet actualBet = new Bet (moneySpent, choice);
actualBet.number();
}
else if (response.equalsIgnoreCase("O"))
{
Bet actualBet = new Bet (moneySpent);
actualBet.odd();
}
else if (response.equalsIgnoreCase("E"))
{
Bet actualBet = new Bet (moneySpent);
actualBet.even();
}
else if (response.equalsIgnoreCase("H"))
{
Bet actualBet = new Bet(moneySpent);
System.out.println(actualBet.high());
}
else if (response.equalsIgnoreCase("L"))
{
Bet actualBet = new Bet (moneySpent);
actualBet.low();
}
else if (response.equalsIgnoreCase("R"))
{
rules();
}
else
{
System.out.println("That is not a choice");
}
}
static void rules()
{
System.out.println("ROULETTE RULES");
System.out.println("-----------------");
System.out.println("If you bet correctly on a NUMBER from 1 to 36 you will earn 10 times your bet\n");
System.out.println("If you bet correctly on a EVEN, ODD, HIGH, or LOW number you will double your bet\n");
System.out.println("IF THE ROULETTE SPINS 0 YOU ALWAYS LOSE\n\n");
System.out.println("BETTING OPTIONS");
System.out.println("-------------------");
System.out.println("N for betting on a NUMBER between 1 and 36");
System.out.println("H for betting on a HIGH number (between 19 and 36)");
System.out.println("L for betting on a LOW number (between 1 and 18)");
System.out.println("O for betting on a ODD number (1, 3, 5, ...)");
System.out.println("E for betting on a EVEN number (2, 4, 6, ...)");
}
}
Here is the new class
Code:
class Bet
{
private int spent;
private int choice;
public Bet(int s)
{
int spent = s;
}
public Bet(int s, int c)
{
int spent = s;
int choice = c;
}
public int number()
{
int earning, number = (int) (Math.random() * 36);
if (number == choice)
{
earning = spent*10;
}
else
{
earning = spent*-1;
}
return earning;
}
public Bet high()
{
int earning, number = (int) (Math.random() * 36);
if (number > 18)
{
earning = this.spent * 2;
}
else
{
earning = this.spent * -1;
}
return new Bet(earning);
}
public int low()
{
int earning, number = (int) (Math.random() * 36);
if (number <= 18)
{
earning = spent*2;
}
else
{
earning = spent*-1;
}
return earning;
}
public int odd()
{
int earning, number = (int) (Math.random() * 36);
if (number%2 != 0)
{
earning = spent*2;
}
else
{
earning = spent*-1;
}
return earning;
}
public int even()
{
int earning, number = (int) (Math.random() * 36);
if(number%2 == 0)
{
earning = spent*2;
}
else
{
earning = spent*-1;
}
return earning;
}
public String toString()
{
return "" + spent;
}
}
I am currently just working with one setter method, high();
When I ask the method to print the output, it print 0.
Any help?