arpita singh

Greenhorn
+ Follow
since Oct 08, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by arpita singh

Hi All,

I am attempting to integrate jQuery Mobile and Struts2 , but inspite of inclung jars and all , the jQM form is not identifying the struts2 action .

What should be done ??
9 years ago
Basically , i need to know how to iterate over elements in a HashMap implemented as an ArrayList of LinkedLists ???
10 years ago
Hi All,

I have elements stored in a HashMap which has been implemented as ArrayList of LinkedLists .
The problem i am facing is how do i iterate over the elements.???

10 years ago
Hi all,

I am implementing module for a scenario where there is a Stock of Products which can be veiwed and added to shopping cart. I am using collections for this , just for sake of practicing Collections.

I am stuck at a point .

For implementation purpose , i have implemented following classes :

Product
Stock
See
MyHashMap
The issue is , MyHashMap extends HashMap and is actually implemented as an ArrayList of LinkedLists .In See i call view_all() , there on converting the mmap (instance of MyHashMap ) to Set
it seems there are no elemnets in the Set as is displayed from output of line 48(comment)



//package p1;

import java.util.*;
import java.io.*;
import java.text.*;
public class Master
{
public static void main(String args[])
{
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(ir);
System.out.println("\n to buy hit 1 \n to window shop hit 2 \n to add to stock hit 3");

try{
Integer i= Integer.valueOf(br.readLine());
switch(i)
{
/*case 1:new Buy().buy();
break;*/
case 2:Stock.addStock();//////////NOTICE effect of sequencing in switch
case 3:new See().see();
//break;
//case 2:new Stock().addStock();
//break;
//default:System.out.println("No valid option chosen");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
System.out.println("You would veiw relevant output shortly");

}
}
}
//////////////////////////////

/*public class CustomColls

{*/

/*static*/ class MyHashMap extends HashMap /* ASK here if i add the generic types in the declaration , as done initially*/
{
//static LinkedList<Product> ArrayList=new ArrayList(LinkedList<Product>);
//LinkedList<Product> []arr=(LinkedList<Product>)arr1;
LinkedList<Product> temp= new LinkedList<Product>();
MyHashMap(){
for(int i=0;i<9;i++)// initialising an array of empty ArrayLists
{

LinkedList<Product> ll= new LinkedList<Product>();

Stock.al.add(i,ll);
}}

public Object put( Object i, Object p)
{
Integer key =(Integer)i;
System.out.println("PUT 111111"+(key%1000));
Product value= (Product)p;
System.out.println("PUT 2222222");
temp=Stock.al.get(key%10);
System.out.println("PUT 333333");
temp.add((Product)p);
System.out.println("PUT 4444444");
System.out.println("added to list");
Stock.count[key%10]++;
Product.count++;
return temp;
}

public LinkedList<Product> get(Object key)
{
Integer i=(Integer)key;
return Stock.al.get(i%10);//////ASK why didn't (Integer)key%10 work???
}
/*boolean get(K k)
{on lync
List l=*/
}
//////////////////////////

class Product
{ static int count=0;
private String gender;
private String category;
private String color;
private int barcode;
private float price;
private int discount;
private String brand;
private Date DateofArrival;
public Date getDateofArrival()
{
return this.DateofArrival;
}

public void setDateofArrival(Date d)
{
this.DateofArrival=d;
}
public String getGender()
{
return this.gender;
}

public String getCategory()
{
return this.category;
}

public String getColor()
{
return this.color;
}

public int getBarcode()
{
return this.barcode;
}

public float getPrice()
{
return this.price;
}

public String getBrand()
{
return this.brand;
}


public void setDiscount(Integer i)
{
this.discount=i;
}


public void setGender(String b)
{
this.gender=b;
}

public void setCategory(String b)
{
this.category=b;
}

public void setColor(String b)
{
this.color=b;
}

public void setBarCode(int b)
{
this.barcode=b;
}

public void setPrice(float b)
{
this.price=b;
}

public void setBrand(String b)
{
this.brand=b;
}

/*public String getGender()
{
return this.gender;
}

public String getGender()
{
return this.gender;
}*/


public int hashCode()
{
int gen=0,cat=0;
String gender=this.getGender().toUpperCase();
String category=this.getCategory().toUpperCase();
for(int i=0;i<gender.length();i++)

gen+=(int)gender.charAt(i);

for(int i=0;i<category.length();i++)
cat+=(int)category.charAt(i);

return(gen+cat);
}
public boolean equals(Product p)
{
//boolean val=false;
System.out.println("in equals");
if((this.getGender().equalsIgnoreCase(p.getGender()))&&(this.getCategory().equalsIgnoreCase(p.getCategory()))&&(this.getColor().equalsIgnoreCase(p.getColor()))&&(this.getColor().equalsIgnoreCase(p.getColor()))&&(this.getBarcode()==p.getBarcode())&&(this.getPrice()==p.getBarcode()))
return true;
else
return false;
}
}

///////////////////////////////////

class Stock
{
static int count[]=new int[9];
static ArrayList <LinkedList<Product>>al =new ArrayList<LinkedList<Product>>();
//static LinkedList<Product> array[]=new LinkedList[8];
static MyHashMap mmap=new MyHashMap();
/// see whether changes to the Map are reflected in its corresponding Collection


public static void addStock()
{
String str="";
//String inputz[]=new String[8];
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(ir);
SimpleDateFormat formatter= new SimpleDateFormat("dd-mm-yyyy");
try
{
System.out.println("maximum of 8 objs cn b inserted");

System.out.println("no. of objs to b inserted");
int c=Integer.valueOf(br.readLine());
for(int i=1;i<=c;i++)
{
/*private String gender;
private String category;
private String color;
private int barcode;
private float price;
private String discount;
private String brand;
private Date DateofArrival;*/



Product p= new Product();
System.out.println("gender,category,color,barcode,price,discount,brand,DateofArrival?");
str+=br.readLine();
String[]inputz=str.split(",");
System.out.println("has read line");
p.setGender((String)inputz[0]);
System.out.println("first in");
p.setCategory(inputz[1]);
p.setColor(inputz[2]);
p.setBarCode(Integer.valueOf(inputz[3]));
System.out.println("2nd in");
p.setPrice(Integer.valueOf(inputz[4]));
System.out.println("3rd in");
p.setDiscount(Integer.valueOf(inputz[5]));
System.out.println(p+""+""+"sm props set");
p.setBrand(inputz[6]);
p.setDateofArrival(formatter.parse(inputz[7]));
System.out.println(p+""+""+"has been set");
LinkedList<Product> itemz=(LinkedList<Product>)mmap.put(new Integer(p.hashCode()),p);
System.out.println(p+""+""+p.hashCode()+"has been added");
System.out.println(itemz);
}
}
catch(Exception e)
{
System.out.println("error");/////////////////ASK: hw cm its running without a try
e.printStackTrace();
}
}
}

////////////////////////////////////////////////////////////////////////////////////////////

class See{
//Collection<ArrayList<LinkedList<Product>>> c= Stock.mmap.values();///////////ASK why didn;t dis wrk ???
//ArrayList<LinkedList<Product>> c= (ArrayList<LinkedList<Product>>)Stock.mmap.values();

//System.out.println(c);
Iterator it=Stock.mmap.entrySet().iterator();
public void see() throws Exception
{
System.out.println("Select your options for the order in which you want to see the items\n 1:View all \n 2 :View price wise \n 3:view Brand wise\n 4:View latest arrivals");
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
Integer i=Integer.valueOf(br.readLine());

switch(i)
{
case 1:view_all();
break;
/*case 2:view_pricewise();
break;
case 3:view_brandwise();
break;
case 4:view_latest();*/

}
}
public void view_all(){
//for(int i=0;i<
System.out.println(it.hasNext());///////////LINE 48
while(it.hasNext()){
System.out.println("ll");
//for(LinkedList<Product> ll :c)
LinkedList<Product> ll=(LinkedList<Product>)it.next();
System.out.println(ll.peekFirst().getBrand());
//ListIterator<Product> li=ll.listIterator(0);
Iterator lt=ll.iterator();
while(lt.hasNext())
{
//LinkedList<Product> ll=li.next();

Product p=(Product)lt.next();
System.out.println(p.getGender()+"\n"+p.getCategory()+"\n"+p.getPrice()+"\n"+p.getColor()+"\n"+p.getBrand());
}
}
}
/*public void view_pricewise(){};
public void view_brandwise(){};
public void view_latest(){};*/

}




Where has it gone wrong ???
10 years ago
Hey guys,

I need to know how excatly does sort() work . Because there is a example in Kathy which is as follows :



Now, what i don't understand here is that ReSortComparator would ultimately be returning -ve,0,or +ve values to indicate which value is greater thean the other . But sort() should always be behaving in a specific manner , no matter we want the order to ascending or descending(reverse, as in here )so while reversing how would sort() know that it has to behave the opposite way as it did while the ascending ordering.


PLzzzzzzzz help me out , i basically need to know how does sort() decide on the relative position'g of the elements in the collection and how does this behavior of it is manipulated while reversing the list.
10 years ago
why is java not a pure object oriented language ?
12 years ago
may i know when during the year can i give the oca 9i certification exam and are there any freely downloadable study materials for it???plzzzzzzz help me out