import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;

 class oldEmployee {

 public static final int length = 0;
static int empid[]={1,2};
static String Name[]={"name1",name2};
 static String State[]={"state1","state2"};
 static String City[]={"city1","city2"};;
 static String Area[]={"area1","area2"};

 public  Employee(int empid,String Name,String State,String City,String Area)
 {
     this.empid=empid;
     this.Name=Name;
     this.State=State;
     this.City=City;
     this.Area=Area;
 }
 public int getEmpId() {
  return empid;
 }
 public void setEmpId(int empid) {
  this.empid = empid;
 }
 public String getName() {
  return Name;
 }
 public void setName(String Name) {
  this.Name = Name;
 }
 public void setState(String State) {
  this.State = State;
  }
 public String getState() {
  return State;
 }
 public static String getCity() {
      return  City;
     }
 public void setCity(String City) {
  this.City = City;
 }
 public String getArea() {
  return Area;
 }
 public void setArea(String Area) {
  this.Area = Area;
 }}

i have emp class with this hardcoded values can anyone help me to achieve this functionality.



    class state
    {
      city[];
     }

    class city
    {
    area[]
    }

    class area
    {
    name[];
    }

in some web application we see country state area. where when we select country all corresponding states are populated in next drop down
and then when we select state all coresponding areas are populated. i want to emp name based on state city area.
states[]

when i select state all

cities[]

then all

areas[]

regards

Edited 4 Years Ago by jinxmc

what exactly is your question? where are you stuck?
for instance, keep in a file an array with the countries:

static String[] countries = {"Belgium","Netherlands","Germany"}; // just an example
//and for each of these countries, you keep an array with cities:
static String[] bCities = {"Antwerp","Brussels"};
static String[] nCities = {"Amsterdam","Den Hague"};
static String[] gCities = {"Berlin","Bonn"};

so here, you'll want to get the cities for a country you choose.
so, in that class, you'll write a getCities-method, which takes a String (the country you chose) as parameter.

in that method:

if ( chosenCountry = Belgium )
return bCities
else if ( chosenCountry = Netherlands )
return nCities
else if ( chosenCountry = Germany )
return gCities
else
throw exception, or return null

Hi,

Thanks for noticing this thread .Actually i have implemented what you have said but my requirement is different .May be i can explain to u

    class oldEmployee {
    public static final int length = 0;
    static int empid[]={1,2};
    static String Name[]={"name1",name2};
    static String State[]={"state1","state2"};
    static String City[]={"city1","city2"};;
    static String Area[]={"area1","area2"};
}


     i have this class old Employee with these properties which are array.i have to break down this class to create new class.


            class state extend oldEmployee {

            should read above state and print cities of corresonding states

            public void printcities( read states)
            {
                take state as parameter and print corresponding cities
                state[0]--state1 its city is city1
                state[1]--state2 its city is city2

            }
            my next class should print area based on cities
            class city extends state
             {
                public void printarea( city)
               this class should print areas based on cities
               city[0]--city1---area1
             }
            }
        ...
        kindly suggest how can i achieve this i am trying but so far not able.i have to use above class with hardcoded values

        regards

well .. you will need the values somewhere, either hardcoded, in a txtfile on your hd, or through some other source.

what I said, is pretty much what you wanted to have, but in a different way.

so, every State (one element of the row state, ArrayList would've been easier, but anyway) has one City (which is on the same index of another array)

so: you have in some (or other source) the possible values.

static String[] states = {"State1","State2"};
static String[] cities = {"City1","City2"};

and in that class, you also add a static method: getCityFromState which takes one parameter: the State.

In that method, you iterate over your states array. if you've found the index, you return the element of cities with that same index.

if, on the other hand, you've iterated over the entire array and have not found that state, you return either null, or throw an exception.

in your calling class, to enter the Statename you want the city for, and if you don't want to have that hardcoded, you have a few options:
you could use Command line parameters, an instance of the Scanner class, or the possibilities offered by the JOptionPane class.

EDIT: but if you are not the person who started this thread, and have a bit different requirements, you probably should 've started another thread, since giving information on two different things might become confusing.

Edited 4 Years Ago by stultuske

This article has been dead for over six months. Start a new discussion instead.