0

can some one help in this code because their is two error in my code.
need reply ASAP. please.

import java.util.*;
public class Card
{
 private int point;
 public Card()
 {
  Random r = new Random();
  //2-10
  point = r.nextInt(10);
  while(point<2)
  {
   point = r.nextInt(10);
  }
  public void setPoint(int p) <--------- illegal start of expression
  {
   point = p;
  }
  public int getPoint()
  {
   return point;
  }
 }
}   <------- class,interface or enum expected

Edited by Nick Evan: Add code-tags

2
Contributors
11
Replies
12
Views
7 Years
Discussion Span
Last Post by jasimp
0

Please wrap your code in code tags, simply highlight your code and click the code button at the top of the reply box. From the unformatted code it appears you are trying to declare a method within your constructor, you might have delimiter, aka bracks... { }, problems as well. Make sure each open { has a close }

Edited by jasimp: n/a

0

"how about the illegal start of expression?"

Sorry I wasn't clear. When I said "it appears you are trying to declare a method within your constructor" I was referring to your illegal start error.

Edited by jasimp: n/a

0

You can't declare a method inside another method, or a constructor. So you need to move your entire setPoint() out of the Card constructor.

0

can u help me with this code.
the error is <cant find sysmbol for br>
thanx....

import java.io.*;
public class blackjack
{
 public static void main(String[] args)throws Exception
 {
  Player p = new Player();
  Dealer d = new Dealer();
  
  Card firstCard = d.generateCard();
  int firstCardValue = firstCard.getPoint();
  System.out.println("Player" + firstCardValue);
  p.setTotal(firstCardValue);
  
  Card secondCard = d.generateCard();
  int secondCardValue = secondCard.getPoint();
  System.out.println("Player" + secondCardValue);
  p.setTotal(secondCardValue);
  
  Card fCard = d.generateCard();
  int fCardValue = fCard.getPoint();
  System.out.println("Dealer" + firstCardValue);
  d.setTotal(firstCardValue);
  
  Card sCard = d.generateCard();
  int sCardValue = sCard.getPoint();
  System.out.println("Dealer" + secondCardValue);
  d.setTotal(secondCardValue);
  
  System.out.println("[1] Hit");
  System.out.println("[2] Stay");
  System.out.println("Choice");
  
  int c = 0;
  while(c!=2)
  {
   if (c==1)
   {
    Card x = d.generateCard();
    int hitValue = x.getPoint();
    p.setTotal(hitValue);
    if (p.getTotal()>21)
    {
     System.out.println("Bust");
     break;
    }
   }
  }
     
     int c2 = Integer.parseInt(br.readline());< cant find sysmbol for br
     if(c==2)
     {
      if(p.getTotal()>d.getTotal())
      {
       System.out.println("You Win");
      }
      else if (p.getTotal()<d.getTotal())
      {
       System.out.println("You Lose");
      }
      else
      {
       System.out.println("Draw");
      }      
     } 
 }
}

Edited by __avd: Add [code] tags. Encase your code in: [code] and [/code] tags.

0

Instantiate, basically, means to create an object. Right now you are trying to call a method, on the object br, yet you haven't created this object yet. Are you taking a class, or learning on your own? This is basic stuff that is generally taught before you start creating your own classes.

Edited by jasimp: n/a

0

yeah i'm learning by my self....self learning i mean
can u send some examples on how to instantiate?

0

Like I said, instantiating is just creating an object, here is the link from the Java tutorials Sun provides.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.