How come I can't call my search method?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How come I can't call my search method?

  1. #1
    Join Date
    Mar 2005
    Posts
    6

    How come I can't call my search method?

    Hi all,

    Don't know why I get a compilation error when I try to call my search method (see below, the last few lines of my code)

    Code:
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    
    class addReservation1
    {
    	static BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
    	
    	//Main Method
    	public static void main (String[]args)throws IOException
    	{
    		String custName, comments;
    		int covers, date, startTime, endTime;
    		int count = 0;
    		Vector oneReservation=null;
    		boolean smoking=true;
    							
    		oneReservation=new Vector();
    		
    		//User can only add one reservation at a time
    		do
    		{
    			
    			System.out.println("Please enter customer's name:");
    			System.out.flush();
    			custName = stdin.readLine();
    				
    			System.out.println("Please enter number of covers:");
    			System.out.flush();
    			covers = Integer.parseInt(stdin.readLine());
    			
    			System.out.println("Please enter smoking or non-smoking (S/N):");
    			System.out.flush();
    			String s= stdin.readLine();
    			String upperS=s.toUpperCase();
    			if (upperS.charAt(0)=='S')
    				smoking = true;
    			else 
    			{if (upperS.charAt(0)=='N')			
    				smoking = false; 
    			}	
    			System.out.println("Please enter date:");
    			System.out.flush();
    			date = Integer.parseInt(stdin.readLine());
    			
    			System.out.println("Please enter start time:");
    			System.out.flush();
    			startTime = Integer.parseInt(stdin.readLine());
    				
    			System.out.println("Please enter end time:");
    			System.out.flush();
    			endTime = Integer.parseInt(stdin.readLine());
    				
    			System.out.println("Please enter comments, if any:");
    			System.out.flush();
    			comments = stdin.readLine();
    			
    			//Instantiate new object
    			oneReservation.addElement(new Reservation(custName,covers,smoking,date,startTime,endTime,comments));
    			
    			count++;
    			
    			System.out.println("Vector contains "+oneReservation.size()+" objects");
    			
    			for (int i=0; i<oneReservation.size();i++)
    			{
    				Reservation r1=(Reservation)oneReservation.elementAt(i);
    				System.out.println(r1.getcustName()+" "+r1.getCovers() +" "+ r1.getSmoking()+" "+ r1.getDate()+" "+r1.getstartTime()+" "+r1.getendTime()+" "+r1.getComments());
    			}
    				
    
    		} 
    		while (count<2);
    		
    	
    		searchcustName("dan", oneReservation);	
    									
    
    				
    		
    
    	}
    }
    Code:
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    
    
    class searchBooking
    {
    		int bookingId;
    		String custName;
    		private Reservation aReservation;
    		Vector v;
    		
    		public Reservation searchcustName(String custName, Vector v)
    		{			
    			    for( int i = 0; i < v.size(); i++) 
    			    {
            			Reservation aReservation = ((Reservation) v.elementAt(i));
            			if ((aReservation.getcustName().equals(custName))) return (aReservation);
            			
            		}
            		return null;
            			
    
    			
    		}
    		
    
    }

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    searchcustName is a method of the searchBooking class not addReservation1, so
    addReservation1 must make itself an instance (new) of searchBooking like
    searchBooking sb=new searchBooking();
    sb.searchcustName ("John Doe", v);

    However it is kind of odd that you seem to regard moethods as classes....
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center