Results 1 to 9 of 9

Thread: help

  1. #1
    kelline is offline Member
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Default help

    gOOd day.. this is a sample program in netbeans 5.5
    and the error is always
    C:\Documents and Settings\comp7.PC7\blackjackapp.java\src\blackjack appjava\blackjackapp\java.java:133: '{' expected
    (StringIndexOutOfBoundsException ex);
    C:\Documents and Settings\comp7.PC7\blackjackapp.java\src\blackjack appjava\blackjackapp\java.java:287: reached end of file while parsing
    }
    what will i do?? plz.... help,,,,,,,,
    tenkz,,godbless


    /*
    * java.java
    *
    * Created on September 16, 2008, 9:53 AM
    *
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    */

    package blackjackappjava.blackjackapp;
    import java.lang.System;
    import java.lang.Integer;
    import java.lang.NumberFormatException;
    import java.io.DataInputStream;
    import java.io.IOException;
    import java.util.Random;
    /**
    *
    * @author comp7
    */
    public class java {

    /** (StringIndexOutOfBoundsException exception); */

    public java() {
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // // BlackJackApp.java

    // Import all the Java API classes needed by this program.

    class BlackJackApp {
    public static void main (String args[]) throws IOException {
    // Create a BlackJackGame object ...
    BlackJackGame game = new BlackJackGame();
    // and play it!
    game.play();
    }
    }

    class BlackJackGame {
    // Variable declarations
    int bet;
    int money;
    Deck deck;
    Hand playersHand;
    Hand dealersHand;
    DataInputStream keyboardInput;

    // Method declarations
    public BlackJackGame() { // Constructor
    bet = 0;
    money = 1000;
    deck = new Deck();
    keyboardInput = new DataInputStream(System.in);
    }

    void play() throws IOException {
    System.out.println("Welcome to Blackjack!");
    System.out.println("You have $"+Integer.toString(money)+".");
    do {
    placeBet();
    if(bet>0) {
    initialDeal();
    if(playersHand.blackjack()) playerWins();
    else{
    while(playersHand.under(22) && playerTakesAHit()) {
    playersHand.addCard(deck.deal());
    playersHand.show(false,false);
    }
    while(dealersHand.mustHit())
    dealersHand.addCard(deck.deal());
    dealersHand.show(true,false);
    showResults();
    }
    }
    } while (bet>0);
    }

    void placeBet() throws IOException, NumberFormatException {
    do{
    System.out.print("Enter bet: ");
    System.out.flush();
    bet = Integer.parseInt(keyboardInput.readLine());
    } while(bet<0 || bet>money);
    }

    void initialDeal() {
    System.out.println("New hand...");
    playersHand = new Hand();
    dealersHand = new Hand();
    for(int i = 0;i<2;++i) {
    playersHand.addCard(deck.deal());
    dealersHand.addCard(deck.deal());
    }
    dealersHand.show(true,true);
    playersHand.show(false,false);
    }

    void playerWins() {
    money += bet;
    System.out.println("Player wins $"+Integer.toString(bet)+".");
    System.out.println("Player has $"+Integer.toString(money)+".");
    }

    void dealerWins() {
    money -= bet;
    System.out.println("Player loses $"+Integer.toString(bet)+".");
    System.out.println("Player has $"+Integer.toString(money)+".");
    }

    void tie() {
    System.out.println("Tie.");
    System.out.println("Player has $"+Integer.toString(money)+".");
    }

    boolean playerTakesAHit() throws IOException {
    char ch = ' ';
    do{
    System.out.print("Hit or Stay: ");
    jipn .ikoSystem.out.flush();
    String playersDecision = keyboardInput.readLine();
    {
    try
    {{ ch = playersDecision.charAt(0);
    }
    }
    catch
    (StringIndexOutOfBoundsException e);
    { if(ch == 'H' || ch == 'h') return true;
    }}
    }}
    if(ch == 'S' || ch == 's') return false;
    }} while(true);
    }

    class Deck {
    // Variable declarations
    int cards[]; // Array of 52 cards
    int topCard; // 0-51 (index of card in deck)
    Random random;

    // Method declarations
    public Deck() { // Constructor
    cards = new int[52];
    for(int i = 0;i<52;++i) cards[i] = i;
    topCard = 0;
    random = new Random();
    shuffle();
    }

    public void shuffle() {
    // Repeat 52 times
    for(int i = 0;i<52;++i) {
    // Randomly exchange two cards in the deck.
    int j = randomCard();
    int k = randomCard();
    int temp = cards[j];
    cards[j] = cards[k];
    cards[k] = temp;
    }
    }

    int randomCard() {
    int r = random.nextInt();
    if(r<0) r = 0-r;
    return r%52;
    }

    Card deal() {
    if(topCard>51) {
    shuffle();
    topCard = 0;
    }
    Card card = new Card(cards[topCard]);
    ++topCard;
    return card;
    }
    } // End of Deck class

    class Hand {
    // Variable declarations
    int numCards;
    Card cards[];
    static int MaxCards = 12;

    //Method declarations
    public Hand() { // Constructor
    numCards = 0;
    cards = new Card[MaxCards];
    }

    void addCard(Card c) {
    cards[numCards] = c;
    ++numCards;
    }

    void show(boolean isDealer,boolean hideFirstCard) {
    if(isDealer) System.out.println("Dealer:");
    else System.out.println("Player:");
    for(int i = 0;i<numCards;++i) {
    if(i == 0 && hideFirstCard) System.out.println(" Hidden");
    else System.out.println(" "+cards[i].value+" of "+cards[i].suit);
    }
    }

    boolean blackjack() {
    if(numCards == 2) {
    if(cards[0].iValue == 1 && cards[1].iValue == 10) return true;
    if(cards[1].iValue == 1 && cards[0].iValue == 10) return true;
    }
    return false;
    }

    boolean under(int n) {
    int points = 0;
    for(int i = 0;i<numCards;++i) points += cards[i].iValue;
    if(points<n) return true;
    else return false;
    }

    int bestScore() {
    int points = 0;
    boolean haveAce = false;
    for(int i = 0;i<numCards;++i) {
    points += cards[i].iValue;
    if(cards[i].iValue == 1) haveAce = true;
    }
    if(haveAce) {
    if(points+10 < 22) points += 10;
    }
    return points;
    }

    boolean mustHit() {
    if(bestScore()<17) return true;
    else return false;
    }

    boolean busted() {
    if(!under(22)) return true;
    else return false;
    }
    } // End of Hand class

    class Card {
    // Variable declarations
    int iValue; // Numeric value corresponding to card.
    String value; // "A" "2" through "9" "T" "J" "Q" "K"
    String suit; // "S" "H" "C" "D"

    // Method declarations
    public Card(int n) { // Constructor
    int iSuit = n/13;
    iValue = n%13+1;
    switch(iSuit) {
    case 0:
    suit = "Spades";
    break;
    case 1:
    suit = "Hearts";
    break;
    case 2:
    suit = "Clubs";
    break;
    default:
    suit = "Diamonds";
    }
    if(iValue == 1) value = "Ace";
    else if(iValue == 10) value = "Ten";
    else if(iValue == 11) value = "Jack";
    else if(iValue == 12) value = "Queen";
    else if(iValue == 13) value = "King";
    else value = Integer.toString(iValue);
    if(iValue>10) iValue = 10;
    }
    int getValue() {
    return iValue;
    }
    { // End of Card class

    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default

    YOur in the wrong part of the forum
    It sounds like you have unpaired {}. Look to see if your IDE has an option to find matching {} and use that to find the missing {}.
    Otherwise print the source and use a pen to connect matching paired {}.
    Start from the inside and work out.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    First of all, you are choosing the wrong forum. I'll move your thread to the correct place, but next time carefully select the forum you exactly need.

    Regarding your question, seems to me the following line incorrect.

    Java Code:
    { // End of Card class
    It should be like this,

    Java Code:
    } // End of Card class
    In NetBeans you can find the {} pair, place the cursor on one of the braces and click the combination Ctrl + { from the key-board, you can easily fins the other braces of the pair.

    Apart from that, please use code tags when you are posting codes next time. And also explain the question with most specific code segment. Testing/reading such a long code can be difficult to others and they may get board on your question.

  4. #4
    jimenezttt is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default

    Hi there Eranga,

    I am a newbie in the programming and wonder if you could help me a bit with this code...

    I was just wondering if there is any way to modify the code on this script so that when it runs, it creates a pdf file for each page inside my doc and named only with numbers for example:

    0.pdf, 1.pdf, 2.pdf, 3.pdf etc.

    This is a script that is meant to run from adobe's Indesign:

    tell application "Adobe InDesign CS3"
    activate
    --set myPageNumPref to page numbering of general preferences


    set myDocument to active document
    set myFileName to name of myDocument
    if (count documents) is equal to 0 then
    display dialog "Please open a document" buttons " OK " default button 1 with icon caution
    return -128
    end if

    set NumberOfPage to pages per document of document preferences of myDocument
    set myFolder to (choose folder with prompt "Please select the folder you want to save your PDF pages in") as string

    --Preset Dialog
    set myLabelWidth to 100
    set myDialog to make dialog with properties {name:"PDF Presets"}
    tell myDialog
    tell (make dialog column)
    tell (make border panel)
    tell (make dialog column)
    tell (make dialog row)
    tell (make dialog column)
    make static text with properties {static label:"Choose Preset:", min width:myLabelWidth}
    end tell
    tell (make dialog column)
    set myLabelsButtons to make radiobutton group
    tell myLabelsButtons
    set PresertList to name of every PDF export preset of application "Adobe InDesign CS3"
    repeat with myButton in PresertList
    make radiobutton control with properties {static label:myButton, checked state:false}
    end repeat
    end tell
    end tell
    end tell
    end tell
    end tell
    end tell
    end tell
    set myResult to show myDialog
    if myResult = true then

    --don't know why but, set myPDFPreset to item (selected button of myLabelsButtons) of PresertList, returns the wrong button. The list starts at 0. So:
    set x to selected button of myLabelsButtons
    set myButtton to x + 1

    set myPDFPreset to item myButtton of PresertList
    end if
    destroy myDialog

    tell myDocument
    with timeout of 5000 seconds
    repeat with x from 1 to NumberOfPage
    set mynumbertest to (name of page x of myDocument) as string
    set mynumbercnt to count of items in mynumbertest
    if mynumbercnt is less than 2 then
    set myPageNumber to "0" & (name of page x of myDocument)
    else
    set myPageNumber to (name of page x of myDocument)
    end if

    set thePath to (myFolder & myPageNumber & " " & myFileName & ".pdf")

    --This is important for setting the page range, the tell has to be to ID
    tell application "Adobe InDesign CS3"
    set page range of PDF export preferences to (x as string)
    export document 1 format PDF type to thePath using PDF export preset myPDFPreset
    end tell
    end repeat
    end timeout
    end tell
    tell application "Adobe InDesign CS3"
    activate
    display dialog "Done!"
    end tell
    end tell

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    jimenez, you do know of course that this is a Java programming forum. I'm not sure what language you are programming with, but I do know that it's not Java, and as such you will probably have to do some searching to find the correct place to post this question. Best of luck.

  6. #6
    jimenezttt is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default

    thank you Fubarable, I apreciate your help. Just in case you want to take a look, I have the actual .js file on this link:

    zenodesign.com/scripts/BatchOnePagePDFs.zip

    Thanks anyways...

  7. #7
    jimenezttt is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default

    sorry, this is the address:

    zenodesign.com/scripts/BatchOnePagePDF2.zip

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    so it's javascript.

    as you know, I'm sure, javascript is a completely different language from java. The only thing that they share is that the syntax of both was borrowed from C, and unfortunately a similar name (done in a marketing ploy). and of course this is a java forum, not a javascript forum. You may wish to search google for a javascript site as there are plenty of them out there.

    Again, best of luck.

  9. #9
    jimenezttt is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •