Need help finding the error in my code Wherever theres a pla

Need help finding the error in my code. Wherever there\'s a \"player.\" something netbeans shows an error saying \"cannot find symbol\".

import java.util.Scanner;


public class DicePlayer {

   private boolean player;
   private String name;
   private double cash;
   Scanner scnr=new Scanner(System.in);
   public void setName()
   {
   System.out.println(\"Enter the name of the player\ \");
   name=scnr.next();
   }
public void setCash ()
   {
   System.out.println(\"Give the amount on the hand\ \");
   cash=scnr.nextDouble();
   }
public String getName()
{
   return name;
}
public double getCash()
{
   return cash;
}
public boolean addCash()
   {
       double add;
System.out.println(\"Give the amount to add\ \");
       add=scnr.nextInt();
       if (add>0)
       {
           cash=cash+add;
           return true;
       }
       else
       return false;
   }
   public boolean subCash()
   {
double sub;
System.out.println(\"Give the amount to sub\ \");
       sub=scnr.nextInt();
       if (sub>0 && sub<cash)
       {
           cash=cash-sub;
           return false;
       }
       else
           return true;
   }
public static void main(String[] args)
    {
        DicePlayer player = new DicePlayer();

        player.setName(\"michael\");
        player.setCash(100);

        System.out.println(\"Hello \"+ player.getName());
        System.out.printf(player.getName() + \", you have $%.2f on hand\ \",player.getCash());


        if(player.addCash(100)) //should work
        {
            System.out.println(\"Added 100 to cash\");
        }
        else
        {
            System.out.println(\"failed to add 100 to cash\");
        }  

        if(player.addCash(-100)) //should fail
        {
            System.out.println(\"Added -100 to cash\");
        }
        else
        {
            System.out.println(\"failed to add -100 to cash\");
        }

        System.out.printf(player.getName() + \", you have $%.2f on hand\ \",player.getCash());


        if (player.subtractCash(12)) //should work
        {
            System.out.println(\"Withdrawal of 12 OK\");
        }
        else
        {
            System.out.println(\"Withdrawal of 12 fail\");
        }

        System.out.printf(player.getName() + \", you have $%.2f on hand\ \",player.getCash());

        if (player.subtractCash(300)) //should fail
        {
            System.out.println(\"Withdrawal of 300 OK\");
        }
        else
        {
            System.out.println(\"Withdrawal of 300 fail\");
        }

         System.out.printf(player.getName() + \", you have $%.2f on hand\ \",player.getCash());

        if (player.subtractCash(-1)) //should fail
        {
            System.out.println(\"Withdrawal of -1 OK\");
        }
        else
        {
            System.out.println(\"Withdrawal of -1 fail\");
}

        System.out.printf(player.getName() + \", you have $%.2f on hand\ \",player.getCash());
  

Solution

I have spotted following errorsin your code:

//private boolean player; // as you are not using this variable , so, i have commented it.
private String name;
private double cash;
Scanner scnr=new Scanner(System.in);
public void setName(String name)
{
System.out.println(\"Enter the name of the player\ \");
// name=scnr.next();
this.name=name;
}
public void setCash (int cash)
{
System.out.println(\"Give the amount on the hand\ \");
//cash=scnr.nextDouble();
this.cash=cash;
}
public String getName()
{
return name;
}
public double getCash()
{
return cash;
}
public boolean addCash(double a)
{
double add;
System.out.println(\"Give the amount to add\ \");
//add=scnr.nextInt();
add=a;
if (add>0)
{
cash=cash+add;
return true;
}
else
return false;
}
public boolean subCash(double s)
{
double sub=s;
System.out.println(\"Give the amount to sub\ \");
// sub=scnr.nextInt();
if (sub>0 && sub<cash)
{
cash=cash-sub;
return false;
}
else
return true;
}
public static void main(String[] args)
{
DicePlayer player = new DicePlayer();

player.setName(\"michael\");
player.setCash(100);

System.out.println(\"Hello \"+ player.getName());
System.out.printf(player.getName() + \", you have $%.2f on hand\ \",player.getCash());


if(player.addCash(100)) //should work
{
System.out.println(\"Added 100 to cash\");
}
else
{
System.out.println(\"failed to add 100 to cash\");
}

if(player.addCash(-100)) //should fail
{
System.out.println(\"Added -100 to cash\");
}
else
{
System.out.println(\"failed to add -100 to cash\");
}

System.out.printf(player.getName() + \", you have $%.2f on hand\ \",player.getCash());


if (player.subCash(12)) //should work
{
System.out.println(\"Withdrawal of 12 OK\");
}
else
{
System.out.println(\"Withdrawal of 12 fail\");
}

System.out.printf(player.getName() + \", you have $%.2f on hand\ \",player.getCash());

if (player.subCash(300)) //should fail
{
System.out.println(\"Withdrawal of 300 OK\");
}
else
{
System.out.println(\"Withdrawal of 300 fail\");
}

System.out.printf(player.getName() + \", you have $%.2f on hand\ \",player.getCash());

if (player.subCash(-1)) //should fail
{
System.out.println(\"Withdrawal of -1 OK\");
}
else
{
System.out.println(\"Withdrawal of -1 fail\");
}}

}

Note : This programs works for only given set of values. if you want to get values from user at runtime ,you can make functions with no input argument and uncomment your code of taking value from user via Scanner class but remember while calling functions dont pass any value.

Need help finding the error in my code. Wherever there\'s a \
Need help finding the error in my code. Wherever there\'s a \
Need help finding the error in my code. Wherever there\'s a \
Need help finding the error in my code. Wherever there\'s a \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site