December 10th, 2012, 02:07 AM
#1
java programming help
hi,
i am new to java.i have been given assignment where i have to display emp name based on state city area.
i have mysql table employee in db with int id[10],name varchar(20),state varchar(20),city varchar(20),area varchar(20));
i have written java program which works properly .where it should display id and name based on state city area.
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;
class OldEmployeeObject {
int id;
String name;
String State;
String city;
String Area;
}
class State {
City[]
}
class City {
Area[]
}
class Area {
Employee[]
}
class Employee {
id;
name;
}
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 SetId(int id)
{
this.id=id;
}
public int getId()
{
return id;
}
public void SetName()
{
this.name=name;
}
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);
while(true)
{
System.out.println("Enter state: ");
String State = br.readLine();
System.out.println("Enter city: ");
String city = br.readLine();
System.out.println("Enter area: ");
String Area = br.readLine();
//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((State.equals(es.State))&& (city.equals(es.city))&& (Area.equals(es.Area)))
{
System.out.print(es.id +" "+ es.name+" " );
//if(id == es.id)
{
System.out.println("The details of the Employeelookup is: ");
System.out.print(es.id +" "+ es.name+" " );
flag = true;
break;
}
}
}
System.out.println(" ");
if(!flag)
{
System.out.println("Sorry, no data exists with the 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;
}
}
}
}
the above program works correctly that accepts state city area from command line searches employee arrays and display emp id and name if its exist.
but i need to create this class structure for employee table.
class state
{
state name->city[]--> it should display state name and array of cities;
state[0]->karnataka
->bangalore
->mysore
-> shimoga
state[1]-->delhi
-->A
-->B
}
my next class
class city
{
city name:area[];
it should display city name-->with array of area[] of that city
city[0]->bangalore.
area[0]-->jayangar
area[1]-->majestic
}
class Area
{
area name-->array of employees;
area[0]-->jayanagar.
emp[o]-->a
emp[1]-->b
area[1]-->majestic
emp[0]-->a
emp[1]-->n
}
basically its like state class
should display array of city[] of each state
and city class should display
all area present in that city
area[]
and area class shoul display all emp from that area
emp[]
regards
December 27th, 2012, 10:08 PM
#2
Re: java programming help
Finally, what is your stuck?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks