Facebook
From Kacper, 5 Years ago, written in Java.
This paste is a reply to Int1 from Kacper - view diff
Embed
Download Paste or View Raw
Hits: 238
  1. public class BookRentals {
  2.         private Vector rentals;
  3.         public String getCustomerName(String rentalId) {
  4.             for (int i = 0; i < rentals.size(); i++) {
  5.                         BookRental rental = (BookRental) rentals.elementAt(i);
  6.  
  7.                         if (rental.getId().equals(rentalId)) {
  8.                                 return rental.getCustomerName();
  9.                         }
  10.                 }
  11.  
  12.                 throw new RentalNotFoundException();
  13.         }
  14.  
  15.         public void deleteRental(String rentalId) {
  16.                 for (int i = 0; i < rentals.size(); i++) {
  17.                         BookRental rental = (BookRental) rentals.elementAt(i);
  18.  
  19.                         if (rental.getId().equals(rentalId)) {
  20.                                 rentals.remove(i);
  21.                                 return;
  22.                         }
  23.                 }
  24.  
  25.                 throw new RentalNotFoundException();
  26.         }
  27. }