FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Java Help

 


asiddle423
This is for all my FRI$'s

Can anyone help me with my java class.

I have the code below.

When i use the method addRental() it will increment the ArrayList and add the data, but my problem is that when I use the findRental() method it returns me with an ArrayList of 0 even when i add records no matter what the ArrayList size is always zero, does anyone know whats wrong with the class

Thanks in advance
Andy

Code:
import java.util.ArrayList;

public class Database {
   
    private ArrayList<Rental> rental;
    private ArrayList<Customer> customer;
    private ArrayList<DVD> dvd;
   
    public Database()
    {
        rental = new ArrayList<Rental>();
        customer = new ArrayList<Customer>();
        dvd = new ArrayList<DVD>();
    }
   
    public void addCustomer(Customer theCustomer)
    {
        customer.add(theCustomer);
        System.out.println("Database: The Customer ArrayList size is " + customer.size());
    }
   
    public void addDVD(DVD theDVD)
    {
        dvd.add(theDVD);
        System.out.println("Database: The DVD ArrayList size is " + dvd.size());
    }
   
    public void addRental(Rental theRental)
    {
        rental.add(theRental);
        System.out.println("Database: The Rental ArrayList size is " + rental.size());
    }
   
    public boolean findRental(int dvdID)
    {
        int size;
        int returnedDvdID;
        boolean toReturn;
       
        toReturn = false;               
        size = rental.size();
       
        System.out.println("Database: size = " + rental.size());
       
        for (int i = 0; i <= (size - 1); i++)
        {
             returnedDvdID = rental.get(i).getDvdID();
             
             System.out.println("Database: retrunedDVDID = " + returnedDvdID);
             System.out.println("Database: dvdID = " + dvdID);
             
             if (dvdID == returnedDvdID)
             {
                 toReturn = true;
             }
        }
       
        return toReturn;
    }
}
Star Wars Fanatic
Hmm... It seems I am missing the rest of your classes, could I have those, please?
Reply to topic    Frihost Forum Index -> Miscellaneous -> Marketplace

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.