Question is below for the TestSlotMachine.

SlotMachine class...

import java.util.Random;
import java.text.NumberFormat;



public class SlotMachine
{
	enum CoinSlot 
    {
		penny, nickel, dime, quarter;
    }
   //private String typeOfMachine;
   public double balance;
   
   
   
   SlotMachine()
   {
   //  typeOfMachine = machineType;
     balance = 0.0;
   }

   public double deposit(double amount)
   {
	   balance = balance + amount;
	   
        return balance;
   }
   
   public String pull(CoinSlot c)
   {

    Random generator = new Random();
   
    int num1 = generator.nextInt(20) + 1;
    int num2 = generator.nextInt(20) + 1;
    int num3 = generator.nextInt(20) + 1;
   // System.out.println (num1 + "," + num2 + "," + num3);
    
    if (num1 == num2 && num1 == num3 && num2 == num3)
    {
         switch(c) {
			case penny:   
			  balance = balance + 0.01;
			  break;
			case nickel:  
			  balance = balance + 0.05;
			  break;
			case dime:
			  balance = balance + 0.10;
			  break;
			case quarter: 
              balance = balance + 0.25;
              break;
        }    
    }    
    else 
    {
          switch(c) {
			case penny:   
			  balance = balance - 0.01;
			  break;
			case nickel:  
			  balance = balance - 0.05;
			  break;
			case dime:
			  balance = balance - 0.10;
			  break;
			case quarter: 
              balance = balance - 0.25;
              break;
          }

    }   
    String stringNum1 = Integer.toString(num1);
    String stringNum2 = Integer.toString(num2);
    String stringNum3 = Integer.toString(num3);
    
    String combine = stringNum1 +" "+ stringNum2 +" "+ stringNum3;
		  return combine;
}
   
   public double getBalance()
   {
	   return balance;
   }
   
   public double cashOut()
   {
	   return balance; 
   }
}

Having trouble with a compile error in the TestSlotMachine below. It says cannot find symbol, symbol: variable quarter
display = quarterMachine(quarter);
________________^
Any ideas on how to resolve?

TestSlotMachine...

import java.util.Scanner;

public class TestSlotMachine
{

	public static void main (String args[]) 
	{		
	
		String type, option, display;
		double depositAmount, balance1, balance2;
		boolean keepGoing;
		
		Scanner scan = new Scanner(System.in);
		
		System.out.println("***************************\n" +
		"* Welcome to Cyber Casino *\n" +
		"***************************\n");
		System.out.println("Type Q(uarter), D(ime), N(ickel), or P(enny)" +
		"to select slot machine type: ");
	    type = scan.nextLine();

        if (type == "q" || type == "Q")
        {    
	    SlotMachine quarterMachine = new SlotMachine();
	    System.out.println("Enter the deposit amount: ");
	    depositAmount = scan.nextDouble();
	    balance1 = quarterMachine.deposit(depositAmount);
	  //  }  
		    if (balance1 >= 0.25) 
	        {
				while (keepGoing == true)
				{
					System.out.println("Type P to pull lever or Q to quit: ");
					option = scan.nextLine();
				
					if (option == "p" || option == "P")
					{
						System.out.print("Display: ");
						display = quarterMachine.pull(quarter);
						System.out.print(display);
						System.out.print("Amount Left: ");
						balance2 = quarterMachine.getBalance();
						System.out.print(balance2); 
						keepGoing = true;
					}
					else if (option == "q" || option =="Q")
					{
						System.out.print("Thank you for visiting us. come again!\n" +
						"your change is: ");
						quarterMachine.cashOut();
						System.out.print(balance2);
						keepGoing = false;
					}	
					else { keepGoing = false; }		
				}
			}	
		}
		else
		{
			System.out.println("Please enter more money");
		}		        
	    
	    SlotMachine NickelMachine = new SlotMachine();
	    SlotMachine DimeMachine = new SlotMachine();
	    SlotMachine QuarterMachine = new SlotMachine();
	    
	    
	}
}

Recommended Answers

All 4 Replies

If you are trying to use the "quarter" enum value, you need to fully qualify it: SlotMachine.CoinSlot.quarter "quarter" is not part of the TestSlotMachine class, so it cannot be used directly.

Thanks, I placed
display = SlotMachine.CoinSlot.quarterMachine.pull(quarter);
there instead but still getting error...

location: class TestSlotMachine
display = SlotMachine.CoinSlot.quarterMachine.pull(quarter);
_______________________________________^
TestSlotMachine.java:45: cannot find symbol
symbol : variable quarterMachine
location: class SlotMachine.CoinSlot
display = SlotMachine.CoinSlot.quarterMachine.pull(quarter);
____________________^
2 errors
Compilation failed


hmmm, any other suggestions?

It is not "quarterMachine" that you need to qualify - it is the "quarter" enum value itself. You are using it as if it were a variable within the TestSlotMachine class, which it is not. That enum is defined in your SlotMachine class as CoinSlot, which is why you have to specify SlotMachine.CoinSlot.quarter if you want to reference the quarter enum value.

Understand now, Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.