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

Thread: Need some help with a couple errors in one of my methods, thanks in advance!

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need some help with a couple errors in one of my methods, thanks in advance!

    Hey guys, really new to java and programming in general here, so bare with me. I'm getting an error here on my choice lines in my getMenuChoice() method, incompatible types because it requires string but has found FootballTeam, what do I have to do here? In my getMenuChoice method I'm getting incompatible types on choice = (footballTeam1); and choice = (footballTeam2);
    Here's my code.

    import java.util.Scanner;
     
    public class FootballGame { 
        static Scanner keyboard = new Scanner(System.in);
        static int arewedone = 0;
        static String choice;
        static FootballTeam team;
     
     
     
     
        public static void main(String[] args) {
              FootballTeam footballTeam1;
              FootballTeam footballTeam2;
     
     
     
     
            System.out.print("Enter a name for a team:");
            footballTeam1 = new FootballTeam(keyboard.nextLine(), 0);
            System.out.print("Enter a name for another team:");
            footballTeam2 = new FootballTeam(keyboard.nextLine(), 0);
     
        do{
            System.out.println("Game Score:");
            System.out.println(footballTeam1.getName() + ":" + footballTeam1.getScore());
            System.out.println(footballTeam2.getName() + ":" + footballTeam2.getScore());
     
            choice = getMenuChoice();
            handleTeamScore(team);
     
        }while(arewedone == 0);
        }
     
        public static String getMenuChoice(FootballTeam footballTeam1, FootballTeam footballTeam2) {
            String input;
            String choice = null;
     
     
     
     
            do {
                System.out.println("Select an option:");
                System.out.println("A:" + footballTeam1 + " scored");
                System.out.println("B:" + footballTeam2 + " scored");
                System.out.println("C: game ended.");
                System.out.println("?:");
                input = keyboard.nextLine();
                if (input.equalsIgnoreCase("A")) {
                    choice = (footballTeam1);
                    arewedone = 0;
                } else if (input.equalsIgnoreCase("B")) {
                    choice = (footballTeam2);
                    arewedone = 0;
                } else if (input.equalsIgnoreCase("C")) {
                    System.out.println("Game Over");
                    arewedone++;
                }
     
     
     
            } while (!input.equals("A") && !input.equals("B") && !input.equals("C"));
           return choice;
     
        }
        public static void handleTeamScore(FootballTeam team) {
     
            int points;
     
            do {
     
                System.out.println("How many points were scored?");
     
                System.out.print("?: ");
     
                points = keyboard.nextInt();
     
                if ((team.addScore(points)) == true) {
     
                    arewedone++;
                } else {
                    System.out.println("That was an invalid option. Please try again.");
                    System.out.println("Hints:");
                    System.out.println("Touchdown = 6 points");
                    System.out.println("Field Goal = 3 points");
                    System.out.println("Safety = 2 points");
                    System.out.println("Extra Point = 1 point");
                        }
                } while (arewedone == 0);
     
        }
     
    }

    Also, did I call my second method correctly within my main method?

    Thanks in advance guys!


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Need some help with a couple errors in one of my methods, thanks in advance!

    Quote Originally Posted by Tonno22 View Post
    so bare with me.
    I'd rather not get naked with you but I can bear with you.

    How many parameters does the getMenuChoice menu expect? How many parameters are you passing when you call the getMenuChoice method?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need some help with a couple errors in one of my methods, thanks in advance!

    Haha, my bad, mistype there! Could you explain that question in detail? I don't really understand it :/ Sorry, I think I'm calling it incorrectly as well.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Need some help with a couple errors in one of my methods, thanks in advance!

    Are you unable to answer my questions? Here's another one. Do you know what a parameter is?
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need some help with a couple errors in one of my methods, thanks in advance!

    I didn't understand the question, and the parameter is the parenthesis in a method name right?

    well, not necessarily a method name, but the parenthesis and what they hold

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Need some help with a couple errors in one of my methods, thanks in advance!

    Yes, the parameters of a method are the things declared inside the parenthesis.
    So go to your getMenuChoice method and count how many parameters there are.
    Then go the where you call the getMenuChoice method and count how many parameters there are?
    Do they match?
    Improving the world one idiot at a time!

  7. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need some help with a couple errors in one of my methods, thanks in advance!

    No they do not match, I should make where I call it choice = getMenuChoice(FootballTeam footballTeam1, FootballTeam footballTeam2); ?


    I'm still getting an error on my call line though, saying that footballTeam2 is already defined in the main method :/

  8. #8
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Need some help with a couple errors in one of my methods, thanks in advance!

    What happened when you tried?
    Improving the world one idiot at a time!

  9. #9
    Junior Member
    Join Date
    Oct 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need some help with a couple errors in one of my methods, thanks in advance!

    I get an error where I call it telling me that footballTeam2 is already defined in the main method :/

Similar Threads

  1. A couple of questions.
    By Sylis in forum Java Theory & Questions
    Replies: 0
    Last Post: October 29th, 2012, 08:32 AM
  2. Couple compile errors for dice game
    By smithmar in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2012, 12:16 PM
  3. A couple of basic java assignments, need help!
    By barnabus in forum Paid Java Projects
    Replies: 1
    Last Post: August 18th, 2010, 10:18 AM
  4. [SOLVED] Handling Errors / calling Error-Catching Methods
    By movsesinator in forum Object Oriented Programming
    Replies: 4
    Last Post: April 6th, 2010, 05:35 AM
  5. [SOLVED] Prime number generator program in Java
    By big_c in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 27th, 2009, 12:08 PM

Tags for this Thread