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 3 of 3

Thread: METHODS!!! HELP

  1. #1
    Junior Member
    Join Date
    Jun 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default METHODS!!! HELP

    Hi I'm new here I have a project due midnight and it'll be greatly appreciated if someone can help me with my code. For my code I have to make a game the game I'm making is war the project MUST be organized using method but everytime I try to make a method I get the follow errors on each of my methods except my main



    HTML Code:
    import java.util.ArrayList;
    import java.util.Scanner;
    import java.util.Random;
     
    class warcardGame {
     
     public static void main(String[] args) {
    
       
       String line = "Welcome to my game of war. " + 
          "The rules of the game are simple " + 
          "Each player turns up a card at the same time and the player with the higher card takes both cards and puts them in their " +
          "respective decks"+
         " If the car1ds are the same rank , then another draw happens"+
          "The game is won when someone has ALL of the cards" + 
           "!!Aces are 14!!";
            
        
        System.out.println(line);
        
       
       Random generator = new Random();
      Scanner reader = new Scanner(System.in);
     
      ArrayList<String> deck = new ArrayList<String>();
      ArrayList<String> userhand = new ArrayList<String>();
      ArrayList<String> computerhand = new ArrayList<String>();
     
     
      public void randNum(){
      ArrayList<Integer> numbers = new ArrayList<Integer>();   
      Random randomGenerator = new Random();
      while (numbers.size() < 52) {
     
          int random = randomGenerator .nextInt(52);
          if (!numbers.contains(random)) {
              numbers.add(random);
          }
      }
     
      public void deckCards(){
      
      deck.add("Ace Of Hearts");
      deck.add("Ace Of Clubs");
      deck.add("Ace Of Spades");
      deck.add("Ace Of Diamonds");
      deck.add("2 of Hearts");
      deck.add("3 of Hearts");
      deck.add("4 of Hearts");
      deck.add("5 of Hearts");
      deck.add("6 of Hearts");
      deck.add("7 of Hearts");
      deck.add("8 of Hearts");
      deck.add("9 of Hearts");
      deck.add("10 of Hearts");
      deck.add("Jack of Hearts");
      deck.add("Queen of Hearts");
      deck.add("King of Hearts");
      deck.add("2 of Diamonds");
      deck.add("3 of Diamonds");
      deck.add("4 of Diamonds");
      deck.add("5 of Diamonds");
      deck.add("6 ofDiamonds");
      deck.add("7 ofDiamonds");
      deck.add("8 ofDiamonds");
      deck.add("9 ofDiamonds");
      deck.add("10 ofDiamonds");
      deck.add("Jack ofDiamonds");
      deck.add("Queen ofDiamonds");
      deck.add("King ofDiamonds");
      deck.add("2 of Clubs");
      deck.add("3 of Clubs");
      deck.add("4 of Clubs");
      deck.add("5 of Clubs");
      deck.add("6 of Clubs");
      deck.add("7 of Clubs");
      deck.add("8 of Clubs");
      deck.add("9 of Clubs");
      deck.add("10 of Clubs"); 
      deck.add("Jack of Clubs");
      deck.add("Queen of Clubs");
      deck.add("King of Clubs");
      deck.add("2 of Spades");
      deck.add("3 of Spades");
      deck.add("4 of Spades");
      deck.add("5 of Spades");
      deck.add("6 of Spades");
      deck.add("7 of Spades");
      deck.add("8 of Spades");
      deck.add("9 of Spades");
      deck.add("10 of Spades");
      deck.add("Jack of Spades");
      deck.add("Queen of Spades");
      deck.add("King of Spades");
     
      
         }
      }
    public void dealCards(){
      for(int i = 0; i<deck.size()/2; i++){
       int firstnumber = numbers.get(i);
       String set = deck.get(firstnumber);
       userhand.add(set);
       }
    }
     
     
      public void dealCardscpu(){
        for(int a = 0; a<deck.size(); a++){
         String checkword = deck.get(a);
         if(userhand.contains(checkword) == false)
          computerhand.add(checkword);
       }
      }
     
      public void warGamecards(){
      while(userhand.size()>0 && computerhand.size()>0){
     
       int l = generator.nextInt(userhand.size()-0);
       int p = generator.nextInt(computerhand.size()-0);
       String cardone = userhand.get(l);
       String cardtwo = computerhand.get(p);
     
       System.out.println("----------------------------------------------------------------------------------------------------------");
       System.out.println("Your : " + cardone);
       System.out.println("Computer Card: " + cardtwo);
       System.out.println("");
       System.out.println("You have " + userhand.size() + " cards.");
       System.out.println("The computer has " + computerhand.size() + " cards.");
       System.out.println("");
     
       System.out.println("If your card is bigger please enter 1.");
       System.out.println("If the computer card is bigger please enter 2.");
       System.out.println("If there is a tie enter 3.");
     
       System.out.print("Enter winner: ");
       int winner = reader.nextInt();
     
       if(winner == 1){
        userhand.add(cardtwo);
        computerhand.remove(p);
       }
     
       if(winner == 2){
        computerhand.add(cardone);
        userhand.remove(l);
       }
     
      }
     
     if(userhand.size() == 0){
       System.out.println("The computer has won the game.");
        System.out.println("THANKS FOR PLAYING");
          System.exit(0);
     }
     if(computerhand.size() == 0){
      System.out.println("You have won the game!!!! :)");
      System.out.println("THANKS FOR PLAYING");
      System.exit(0);
     
       }
     
     }
     
    }[HTML]
    [/HTML]

  2. #2
    Member
    Join Date
    May 2017
    Location
    Eastern Florida
    Posts
    68
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: METHODS!!! HELP

    everytime I try to make a method I get the follow errors
    Can you copy the full text of the error messages and paste it here so we can see what the compiler is complaining about?

    Please wrap the code with CODE tags not HTML tags.

    The code's formatting needs to be properly indented so that it can be read and understood.
    Too many nested statements are not indented to show the logic.
    Last edited by NormR; June 14th, 2017 at 07:45 PM.

  3. #3
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: METHODS!!! HELP

    Please post the errors
    Whatever you are, be a good one

Similar Threads

  1. Returning methods to main() and other methods
    By jonmackey22 in forum Object Oriented Programming
    Replies: 4
    Last Post: September 25th, 2014, 04:36 PM
  2. methods
    By tugcegunes in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 9th, 2014, 06:21 AM
  3. [SOLVED] Help with Methods
    By Blasfemmy in forum What's Wrong With My Code?
    Replies: 24
    Last Post: October 22nd, 2012, 08:18 PM
  4. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 01:16 AM
  5. Re-using methods?
    By Morevan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2010, 05:04 PM