java - Error: actual and formal argument lists differ in length. Object-Oriented Programming -


so doing first object oriented programming assignment , coming error when try , compile:
winner = rps.pickwinner(userchoice, cpuchoice); //***your method ^ required: no arguments found: string,string reason: actual , formal argument lists differ in length appreciated.

    import java.util.scanner;  **strong text**public class kyleabelweek10 {  public static void main(string[] args) {     scanner in = new scanner(system.in);     rockpaperscissors rps = new rockpaperscissors();  //***your class      int numgames = 0;     string userchoice = "";     string cpuchoice = "";     string winner = "";     int userwins = 0;     int cpuwins = 0;       system.out.println("welcome rock, paper, scissors!\n");      //get odd number of games     system.out.println("how many rounds play?");     numgames = in.nextint();      while (numgames % 2 == 0) //even number     {         system.out.println("sorry, number of games must odd.  please try again:");         numgames = in.nextint();     }      //flush buffer     in.nextline();      //play game number of rounds user entered     (int = 1; <= numgames; i++) {         //get user , computer choices         userchoice = rps.getuserchoice();  //***your method         cpuchoice = rps.getcpuchoice();   //***your method          system.out.println("computer chooses " + cpuchoice);          //pick winner         winner = rps.pickwinner(userchoice, cpuchoice);  //***your method          if (winner.equalsignorecase("tie")) {             system.out.println("it's tie!  play again.");             numgames++;         } else {             if (winner.equalsignorecase("user")) {                 userwins++;             } else if (winner.equalsignorecase("computer")) {                 cpuwins++;             } else {                 system.out.println("error in picking winner");             }              system.out.println(winner + " wins!");         }      } //end      //print results     system.out.println("\nuser wins: " + userwins);     system.out.println("computer wins: " + cpuwins);      if (userwins > cpuwins) {         system.out.println("\nthe user won!");     }     if (cpuwins > userwins) {         system.out.println("the computer won!");     }      //close game     system.out.println("\nthank playing!");  } //end main  }      import java.util.*; public class rockpaperscissors {    public string getuserchoice ()    {       //utility       scanner in = new scanner(system.in);       //variables       string userchoice = "";         system.out.println("rock, paper, or scissors?:");       userchoice = in.nextline();        while (!userchoice.equalsignorecase("rock") && !userchoice.equalsignorecase("paper") && !userchoice.equalsignorecase("scissors"))       {           system.out.println("sorry," + userchoice + " not valid entry.please enter rock, paper, or scissors.");           userchoice = in.nextline();        }       return userchoice;   }   public string getcpuchoice ()   {        //get random number       random r = new random ();        //variables          int randomnumber = 0;       string cpuchoice = "";        //make random choice         randomnumber = r.nextint(3)+1;           if (randomnumber == 1)         {          cpuchoice = ("rock");         }         if (randomnumber == 2)         {         cpuchoice = ("paper");         }         if (randomnumber == 3)         {         cpuchoice = ("scissors");         }          return cpuchoice;    }      public string pickwinner ()    {         //variables         string winner = "";       string userchoice = "";       string cpuchoice = "";        //decide wins round         if (userchoice.equalsignorecase("rock"))         {            if (cpuchoice.equalsignorecase("scissors"))            {               winner = ("user");            }            else if (cpuchoice.equalsignorecase("paper"))            {               winner = ("computer");            }            else            {               winner = ("tie");            }          }          else if (userchoice.equalsignorecase("paper"))         {            if (cpuchoice.equalsignorecase("scissors"))            {               winner = ("computer");            }            else if (cpuchoice.equalsignorecase("rock"))            {               winner = ("user");            }            else            {               winner = ("tie");            }         }          else if (userchoice.equalsignorecase("scissors"))         {            if (cpuchoice.equalsignorecase("rock"))            {               winner = ("computer");            }            else if (cpuchoice.equalsignorecase("paper"))            {               winner = ("user");            }            else            {                winner = ("tie");            }         }               return winner;    }   

}

your rockpaperscissors class defines:

public string pickwinner () 

meaning has no parameters. , yet main calls it:

winner = rps.pickwinner(userchoice, cpuchoice); 

one of wrong , need changed.


most it'll rockpaperscissors function since already have user , computer choices before calling it. i'd changing:

public string pickwinner () {      string winner = "";     string userchoice = "";     string cpuchoice = ""; 

into:

public string pickwinner (string userchoice, string cpuchoice) {      string winner = ""; 

for it's worth, make function little more readable like:

public string pickwinner (string userchoice, string cpuchoice)     if (userchoice.equalsignorecase("rock")) {         if (cpuchoice.equalsignorecase("scissors"))             return "user";         if (cpuchoice.equalsignorecase("paper"))             return "computer";         return "tie";     }      if (userchoice.equalsignorecase("scissors")) {         if (cpuchoice.equalsignorecase("paper"))             return "user";         if (cpuchoice.equalsignorecase("rock"))             return "computer";         return "tie";     }      if (userchoice.equalsignorecase("paper")) {         if (cpuchoice.equalsignorecase("rock"))             return "user";         if (cpuchoice.equalsignorecase("scissors"))             return "computer";         return "tie";     }      return "???" } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -