
I have employee class that displays employee information based on id .
class employee
{
int id;
String name;
String State;
String City;
String Area;
}
Now i need to display **employee name** based on state ,city,area present in the employee class how to achive this in java and swing any suggestion would be useful. i.e when i select state it should display all states present in employee class then when i select state it should display all city present in the class corresponding to that state ,then it should display area corresponding to that city in that class.
import java.util.ArrayList;
import java.io.*;
public class Employeelookup {
static ArrayList<Employeelookup> al = new ArrayList<Employeelookup>();
int id;
String name;
String State;
String city;
String Area;
static int count = 0;
{
}
Employeelookup()
{
}
Employeelookup(int id, String name, String State,String city,String Area)
{
this.id = id;
this.name = name;
this.State=State;
this.city=city;
this.Area=Area;
count++;
}
public void putDetails(Employeelookup e)
{
al.add(e);
}
public Employeelookup getDetails(int id)
{
Employeelookup es = (Employeelookup)al.get(id);
return es;
}
public static void main(String[] args ) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Employeelookup e = new Employeelookup();
Employeelookup e1 = new Employeelookup(1, "SaiRam", "karnataka","bangalore","rajajinagar");
Employeelookup e2 = new Employeelookup(2, "Anu", "karnataka","mysore","temple road");
Employeelookup e3 = new Employeelookup(3, "Vasu", "karnataka","bangalore","rajajinagar");
Employeelookup e4 = new Employeelookup(4, "Shillu", "Tamil Nadu","madhurai","b");
Employeelookup e5 = new Employeelookup(5, "Madhu", "Karnataka","shimoga","bus stop");
Employeelookup e6 = new Employeelookup(6, "Volga", "Andra","abc","railway stop");
e.putDetails(e1);
e.putDetails(e2);
e.putDetails(e3);
e.putDetails(e4);
e.putDetails(e5);
e.putDetails(e6);
System.out.println("The total number of Employeelookups are: " +count);
System.out.println(" ");
while(true)
{
System.out.println("Enter Employeelookup id to get the Employeelookup details: ");
int id = Integer.parseInt(br.readLine());
boolean flag = false;
for(int i=0; i <al.size();i++) {
Employeelookup es = e1.getDetails(i);
if(id == es.id)
{
System.out.println("The details of the Employeelookup with id " +id +" is: ");
System.out.print(es.id +" " +es.name+" " +es.State);
flag = true;
break;
}
}
System.out.println(" ");
if(!flag)
{
System.out.println(" no data exists with the id " +id);
}
System.out.println(" ");
String ch = null;
while(true)
{
System.out.println("Want to Continue(y/n)?)");
System.out.println(" ");
ch = br.readLine();
if(ch.equalsIgnoreCase("y") || ch.equalsIgnoreCase("n")) break;
if(!(ch.equalsIgnoreCase("y") || ch.equalsIgnoreCase("n")))
{
System.out.println("Invalid option : please type y/n");
System.out.println(" ");
}
}`print("code sample");`
print("code sample");
if(ch.equalsIgnoreCase("n"))
{
System.out.println(" ");
System.out.println("exit");
break;
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.