Results 1 to 8 of 8
- 09-04-2010, 04:07 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 6
- Rep Power
- 0
which classes to write..how to program this?
11. Create a class called Families which creates a one-to-many mapping of parent name (String) to Child objects. Create any needed member variables and write the two specified methods.
class Families {
public void addToFamily( String parent, Child child) {
}
public List<Child> getChildren( String parent) {
}
}
-
Thanks for posting your assignment. I assume that you are going to show the fruits of your efforts and then ask a direct question, correct?
- 09-04-2010, 04:16 AM #3
Any exception text?
- 09-04-2010, 04:24 AM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
- 09-04-2010, 04:43 PM #5
Member
- Join Date
- Aug 2010
- Posts
- 6
- Rep Power
- 0
why a null pointer exception?
import java.util.HashMap;
import java.util.List;
class Families {
HashMap<String,List<String>> hm=new HashMap<String,List<String>>();
void find(String parent,String child)
{
List<String> l = hm.get(parent);
if(l.isEmpty()== true)
{
List list = null;
list.add(child);
hm.put(parent, list);
}
else
{
// parent already exists
l.add(child);
}
}
//public void addToFamily( String parent, Child child)
//{
//a=find(parent);
//}
public List<String> getChildren( String parent)
{
List l=null;
l=hm.get(parent);
return l;
}
public static void main(String args[])
{Families ob=new Families();
ob.find("nav","khushi");
ob.find("nav", "soni");
ob.find("nav", "vish");
ob.find("ash", "sonu");
List li=null;
li=ob.getChildren("naveen");
System.out.println(li);
}
}
- 09-04-2010, 04:48 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
- 09-04-2010, 05:15 PM #7
Member
- Join Date
- Aug 2010
- Posts
- 6
- Rep Power
- 0
how to get rid of this error then?
also the question was this..
i m suppose to vreate parent child mapping
how m i suppose to cretae the parent and child class?
this is not an assignment question as pointed out by the moderator.
It was asked in one of the interviews..and i ws nt able to answer it.
class Families {
public void addToFamily( String parent, Child child) {
}
public List<Child> getChildren( String parent) {
}
}
- 09-04-2010, 06:12 PM #8
Similar Threads
-
How to write two server program in java
By priyamurugar in forum NetworkingReplies: 1Last Post: 04-27-2010, 11:20 AM -
ok so i have to write a program called FourRectanglePrinter
By jcoon3 in forum New To JavaReplies: 0Last Post: 09-22-2009, 07:15 PM -
is it possible to write program with out thread
By makpandian in forum Threads and SynchronizationReplies: 3Last Post: 12-21-2008, 05:41 PM -
How to write interceptor program in struts2?
By vasu in forum Web FrameworksReplies: 1Last Post: 10-07-2008, 07:53 AM -
need help to write Program in JAVA
By maneibr in forum New To JavaReplies: 1Last Post: 03-13-2008, 01:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks