This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

create a new class from this existing employee class to display cascading drop down to display

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

in my project i have class Employee with details of id,name,age,state,city,area i have hard coded these values. Now i want to create class from this existing class to display emp name based values of state city area.

When i select state all states should be displayed.then corresponding city of state should be displayed and then area based on previous value of city and the all employee name who are from this city.

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("Sorry, 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(" ");
}
}

if(ch.equalsIgnoreCase("n"))
{
System.out.println(" ");
System.out.println("Thank you");
break;
}
}
}
}



 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags when posting code.

Your Employeelookup class should be split in to at least 2 separate classes, one to do the lookup the other to hold the employee data. Depending on what you are doing you could arguably also have a 3rd class which is a collection of employees.

You haven't said what is wrong with your code or asked a question so I can't offer any further advice at the moment.
 
unknown mc
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have employee class with these hardcoded values now i need to do display emp id and name based on state && city and && area of this class in java .

like in some web application when we select state ,city,area, it display its pincode like that .can you advice me how shall i proceed
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!