java - receiving and returning methods -


i trying write simple program calls various methods prompts user city , state name , population gives percentage of population. i've gotten of code down keep getting 1 compiler error says

"error: cannot find symbol, variable: citypercstate"

can tell me whats wrong in code?

import java.util.scanner;  public class cityorozcob52  { // begin class   private static scanner input = new scanner(system.in);    public static void main(string[] args)    { // begin main method      string city, state;     float citypopulation, statepopulation;        cityname();     statename();     citypopulation(city);     statepopulation(state);     citypercstate(citypopulation, statepopulation);     displaycitystatestats(city, state, citypopulation, statepopulation, citypercstate);     } // end main method    public static string cityname()   {     string city = "";     system.out.printf("what name of city:");      city = input.nextline();       return city;   }    public static string statename()   {     string state = "";     system.out.printf("what name of state:");     state = input.nextline();      return state;   }    public static float citypopulation(string city)   {     float citypopulation = 0;     system.out.printf("what population of %s:\n", city);     citypopulation = input.nextfloat();      return citypopulation;    }   public static float statepopulation(string state)   {     float statepopulation = 0;     system.out.printf("what population of %s:", state);     statepopulation = input.nextfloat();      return statepopulation;   }    public static float citypercstate(float citypopulation, float statepopulation)   {    float citystatepercentage = (citypopulation / statepopulation) * 100;    }    public static void displaycitystatestats(string cityname, string statename, float citypopulation, float statepopulation,                                        float citypercstate)   {    system.out.printf("population statistics\n\n"                     + "city: %s"                     + "state: %s"                     + "city population: %f"                     + "state population: %f"                     + "city state population: %.2f%%", cityname, statename, citypopulation, statepopulation,                                                            citypercstate);    } } // ends cityorozcole52 

you need return value in citypercstate() method.

so add:

return citystatepercentage;  

to method.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -