?
Solved

Vector

Posted on 2005-04-01
10
Medium Priority
?
209 Views
Last Modified: 2010-03-31
I am having problems listing all the details of my objects.

MedicalConsole.java is the driver program.

You can download the code from:

www.chakracs.com/ourlady/medical.zip

Your help is kindly appreciated.

Regards

Eugene
0
Comment
Question by:eugene007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 13680853
What exactly is the problem? Also - why do you have that infinite while-loop in the main () method?
0
 

Author Comment

by:eugene007
ID: 13680868
The problem is when I attemp to list the details of an object, it displays nothing.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13680916
Is it in your listMedicalFacility () method? That method has the following code, as I see:

>> public static void listMedicalFacility()
>> {
>>           Vector mf = hs.getmedicalFacilities();
>>           Iterator iter = mf.iterator();
>>                          
>>           while(iter.hasNext())
>>           {
>>                         
>>           }
>>}

It has a blank while-loop. You're not printing anything there.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:eugene007
ID: 13680951
I have problems in this part of the code:

public static void listMedicalFacility()
{
     Vector mf = hs.getmedicalFacilities();
     Iterator iter = mf.iterator();
                          
     while(iter.hasNext())
     {
                         
     }
}
        
      
public static void listPatient()
{
    Vector ps = hs.getPatients();
    Iterator iter = ps.iterator();
                          
    while(iter.hasNext())
    {
             Patient p = (Patient) iter.next();
             System.out.println(p);    
    }
}

               
public static void listProcedure()
{
     Vector pr = hs.getmedicalFacilities();
     Iterator iter = pr.iterator();
                          
     while(iter.hasNext())
     {
             Procedure p = (Procedure) iter.next();
             System.out.println(p);    
     }
}                          
0
 

Author Comment

by:eugene007
ID: 13680968
>> public static void listMedicalFacility()
>> {
>>          Vector mf = hs.getmedicalFacilities();
>>          Iterator iter = mf.iterator();
>>                       
>>          while(iter.hasNext())
>>          {
>>                         
>>          }
>>}

I tried this:

>> public static void listMedicalFacility()
>> {
>>          Vector mf = hs.getmedicalFacilities();
>>          Iterator iter = mf.iterator();
>>                       
>>          while(iter.hasNext())
>>          {
>>                     if(iter.next instanceof Hospital)
                          {
                                  Hospital h = (Hospital)iter.next
                                  System.out.println(h);      
                          }  
>>          }
>>}

I am getting error msg.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13680987
What is the error message?
0
 

Author Comment

by:eugene007
ID: 13681026
public static void listMedicalFacility()
{
        Vector mf = hs.getmedicalFacilities();
        Iterator iter = mf.iterator();
                          
        while(iter.hasNext())
        {
                    if(iter.next() instanceof Hospital)
                    {
                         Hospital h = (Hospital) iter.next();
                         System.out.println(h);
                     }
       }
}




the error that I receive is exception in thread, for the code above.

0
 
LVL 30

Accepted Solution

by:
Mayank S earned 360 total points
ID: 13681042
Yes, but what is the exception-message? Anyway, why are you calling next () two times? You should call it only once. Perhaps you are getting a ClassCastException.

public static void listMedicalFacility()
{
        Vector mf = hs.getmedicalFacilities();
        Iterator iter = mf.iterator();
                       
        while(iter.hasNext())
        {
                    Object o = iter.next () ;

                    if ( o instanceof Hospital )
                    {
                         Hospital h = ( Hospital ) o ;
                         System.out.println(h);
                     }
       }
}
0
 

Author Comment

by:eugene007
ID: 13681218
ok that works as for the

public static void listProcedure()
{
      Vector mf = hs.getmedicalFacilities();
      Iterator iter1 = mf.iterator();
                                            
      while(iter1.hasNext())
      {
              Object o = iter1.next();
                                     
              if(o instanceof Hospital)
              {
                    Hospital h = (Hospital) o;           
                    Vector pr = h.getProcedures();
 
                    Iterator iter2 = pr.iterator();
          
                    while(iter2.hasNext())
                    {
                         Procedure p = (Procedure) iter2.next();
                         System.out.println(p);    
                    }
              }
       }
}

would it be right to code it this way?.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13688701
Yeah, that's fine.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question