I am a Java rookie and completely lost. I need to implement a phone directory us
ID: 3645435 • Letter: I
Question
I am a Java rookie and completely lost. I need to implement a phone directory using a vector and demonstrate a variety of features. The entries must contain name, home, cell, and work phone numbers. The main method should load several entries into the book and demonstrate the ability to:Search for a person's numbers based on his or her name.
Search for a person's contact information based on his or her work number.
Remove entries from your directory.
Print all the entries in the directory.
Return the entry at a specific index.
If a name or work phone number does not exist, your program should print out that the name was not found.
I have started some code but I'm not sure how much sense it makes....
public class PhoneDirectory extends Vector
{
static BufferedReader keyboard = new BufferedReader (new
InputStreamReader (System.in));
public PhoneDirectory()
{
super();
}
public void addEntry(String name, String homeNumber, String workNumber, String cellNumber)throws IOException
{
Vector<Object> phoneEntry = new Vector<Object>();
public String getName(String name) throws IOException
{
System.out.print("Input the Employee name :");
name= keyboard.readLine();
return name;
}
public String getHomeNumber(String homePhone) throws IOException
{
System.out.print("Input the Employee name :");
homePhone= keyboard.readLine();
return homePhone;
}
public String getWorkNumber(String workPhone) throws IOException
{
System.out.print("Input the Employee name :");
workPhone= keyboard.readLine();
return workPhone;
}
public String getCellNumber(String cellPhone) throws IOException
{
System.out.print("Input the Employee name :");
cellPhone= keyboard.readLine();
return cellPhone;
}
phoneEntry.addElement(name, homeNumber, workNumber, cellNumber);
}
/**
* @param args the command line arguments
*/
}
Explanation / Answer
When the C++ orb receives a java.util.Vector from a Java 1.4.2 partner, a CORBA::MARSHAL will be returned to the application program. Java 1.4.2 has changed the java.util.Vector class and it is no longer compatible with the version of Java that the C++ was built upon (Java 1.3.0), so the C++ orb will not be able to interact with its Java partner with this class. The C++ will now return a CORBA::NO_IMPLEMENT in this situation. Also, the valuetype sample program that is shipped with the C++ SDK (ValuetypeSampleClient), will now fail when it is communicating with a WebSphere Application Server that is using Java 1.4.2 or above. Following is an example of what the output will be from ValuetypeSampleClient.exe : ======================================== initializing orb receiving phone numbers (java.util.Vector of strings) ERROR: CORBA::NO_IMPLEMENT exception, minor = 1330446338, was received. The server is using a version of the java.util.Vector class that is incompatible with the version used by this client (JDK 1.3.0). receiving custom valuetype (Address) street = "1600 Pennsylvania Avenue". city = "Washington DC". zip = 20500 removing bean ValuetypeSampleClient completed with failures! ======================================= Local fix Problem summary **************************************************************** * USERS AFFECTED: WebSphere C++ CORBA SDK application * * developers * **************************************************************** * PROBLEM DESCRIPTION: C++ ORB throws a CORBA::MARSHAL * * exception when it receives a * * java.util.Vector from a Java 1.4.2 or * * greater partner ORB, or a * * javax.ejb.CreateException from a * * Java 1.4.1 or greater partner ORB. * **************************************************************** * RECOMMENDATION: * **************************************************************** When the C++ ORB receives a java.util.Vector from a Java 1.4.2 or greater partner ORB, or a javax.ejb.CreateException from a Java 1.4.1 or greater partner ORB, a CORBA::MARSHAL exception is returned to the application program. Problem conclusion Java 1.4.2 changed the java.util.Vector class, and Java 1.4.1 changed the javax.ejb.CreateException class and they are no longer compatible with the version of Java (1.3.0) upon which the C++ ORB was based. It is not possible for the C++ ORB to process these objects. It is within the CORBA spec for an ORB to not be able to handle an object. The problem is that the C++ ORB was throwing a CORBA::MARSHAL exception in this case, which is not within the CORBA spec. It should be throwing a CORBA::NO_IMPLEMENT exception. The WebSphere C++ CORBA SDK was changed so that it would throw a CORBA::NO_IMPLEMENT exception in these cases. The CORBA spec and the resolution are also more generic than this. If the C++ ORB receives any object that it has an implementation for, but whose signature doesn't match (like java.util.Vector for example), a CORBA::NO_IMPLEMENT exception will be thrown. If any object is received that the ORB can identify as an object, but it has no implementation for at all, a CORBA::NO_IMPLEMENT exception will be thrown. An example of the latter would be a user-defined object sent from a server to a client, as opposed to standard Java objects. The CORBA::NO_IMPLEMENT exceptions thrown in these two cases would have different minor codes. If it is important for the application developer to know the minor codes, the CORBA specification should be referred to.Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.