Facebook
From Kacper, 5 Years ago, written in Java.
This paste is a reply to Int1 from Kacper - go back
Embed
Viewing differences between Int1 and Re: Int1
public class BookRental {
        String id;
        String customerName;

        ...
}

public class BookRentals {
        private Vector rentals;
        public String getCustomerName(String rentalId) {
                for (int i = 0; i < rentals.size(); i++) {
                        BookRental rental = (BookRental) rentals.elementAt(i);
elementAt(i);

                        if (rental.getId().equals(rentalId)) {

{
                                return rental.getCustomerName(); getCustomerName();
                        }
                }

                throw new RentalNotFoundException();
        }

        public void deleteRental(String rentalId) {
                for (int i = 0; i < rentals.size(); i++) {
                        BookRental rental = (BookRental) rentals.elementAt(i);

                        if (rental.getId().equals(rentalId)) {
                                rentals.remove(i);
                                return;
                        
}
                }

                throw new RentalNotFoundException();
        }
}

public class RentalNotFoundException extends Exception {
        ...
}