Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Simple game in Java

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Simple game in Java

    How can I make my program read the input 'Higher' or 'Lower'?

         PlayingCard cardOne = new PlayingCard();
         PlayingCard cardTwo = new PlayingCard();
     
         double, bank, bet;
          System.out.print("\n\nHow much is in your bank? "); 
          bank = scan.nextDouble(); 
          System.out.print("\n\nHow much would you like to bet? "); 
          bet = scan.nextDouble(); 
          if (bet > 100)
          {
          System.out.println("Sorry, your bet was too high.");
          }
          if (bet > bank)
          {
          System.out.println("Sorry, your bet was too high.");
          }
          System.out.println("Do you think the second card will be higher or lower?");
          String Input = scan.nextLine(); 
    if (cardOne.getFace() < cardTwo.getFace() && Input.equals("higher"))
                                   do
                                   {
                                        cardTwo.drawCard();
                                   }
                                   while (cardOne.isEquals(cardTwo));


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Location
    Home-Ujjain /Job-Mumbai
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wink Re: Simple game in Java

    Use the following

    String inputValue = JOptionPane.showInputDialog("Please input a value");

    and pasrse the input if you want any int or any other type

    you can also use System.in.read() as follows
    import java.io.IOException;
     
    public class MainClass {
     
      public static void main(String[] args) {
        int inChar;
        System.out.println("Enter a Character:");
        try {
          inChar = System.in.read();
          System.out.print("You entered ");
          System.out.println(inChar);
        }
        catch (IOException e){
          System.out.println("Error reading from user");
        }
      }
    }
    Programmer

Similar Threads

  1. Need help for my java game
    By blunderblitz in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 27th, 2010, 05:32 AM
  2. Replies: 8
    Last Post: December 9th, 2009, 04:45 PM
  3. Java hangman game help...
    By AnotherNoob in forum AWT / Java Swing
    Replies: 16
    Last Post: December 4th, 2009, 11:17 PM
  4. Simple Game In Java (Head and Tails).
    By drkossa in forum Java Theory & Questions
    Replies: 5
    Last Post: November 28th, 2009, 11:40 AM
  5. Problem while programming a simple game of Car moving on a road
    By rojroj in forum Java Theory & Questions
    Replies: 3
    Last Post: April 2nd, 2009, 10:24 AM