public class Men {
private int id;
private String name;
private float price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
####################################################################
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class MapDemo {
public static void main(String[] args) {
ArrayList a=new ArrayList();
for(int i=0;i<10 div="" i="">
10>
Men m=new Men();
m.setId(i);
m.setName("men"+i);
m.setPrice(200*i);
a.add(m);
}
ArrayList b=new ArrayList();
for(int i=0;i<10 div="" i="">
Men m=new Men();
m.setId(i);
m.setName("women"+i);
m.setPrice(200*i);
b.add(m);
}
HashMap>shoping=new HashMap();
shoping.put("men",a);
shoping.put("women",b);
Set s=shoping.keySet();
int i=0;
for(String t:s){
System.out.println("press "+(i+1) +" for " + t.toUpperCase());
i++;
}
Scanner ss=new Scanner(System.in);
System.out.println("Enter your Choice : ");
int choice=ss.nextInt();
System.out.println(choice);
switch(choice){
case 1:
List list=shoping.get("men");
for(Men mm:list){
System.out.println(mm.getId()+"\t"+mm.getName()+"\t"+mm.getPrice());
}
break;
case 2:
List list1=shoping.get("women");
for(Men mm:list1){
System.out.println(mm.getId()+"\t"+mm.getName()+"\t"+mm.getPrice());
}
break;
default:
}
}
}
10>
No comments:
Post a Comment