Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. String rNum1;
  2. String afm1;
  3. Date rentDate, retDate;
  4. rNum1 = reader.readString("Vehicle Registration Number: ");
  5. afm1 = reader.readString("Client AFM: ");
  6. rentDate = reader.readDate("Rent Date: ");
  7. retDate = reader.readDate("Return Date: ");
  8.  
  9. /* Using the object cc of a constructor i call the method findRentals that takes the input variables of the user.*/
  10.  
  11. cc.findRentals(rNum1, afm1, rentDate, retDate);
  12. /* Method findRentals */
  13. public Rental findRentals(String rNum, String afm, Date rentDate, Date retDate) {
  14.  
  15. /* I initialized data into the object rental */
  16.  
  17. rentals.insert(new RentalItem(new Rental(100, cc.findClient("123456789"), cc.findVehicle("XNK5544"), new Date("3/4/2019"), new Date("22/4/2019"), 950)));
  18. rentals.insert(new RentalItem(new Rental(101, cc.findClient("987456321"), cc.findVehicle("XNA1204"), new Date("4/5/2019"), new Date("4/8/2019"), 210)));
  19. rentals.insert(new RentalItem(new Rental(102, cc.findClient("741258963"), cc.findVehicle("XNO1706"), new Date("6/5/2019"), new Date("6/15/2019"), 405)));
  20. rentals.insert(new RentalItem(new Rental(103, cc.findClient("258963147"), cc.findVehicle("XNX9901"), new Date("6/5/2019"), new Date("6/15/2019"), 240)));
  21. rentals.insert(new RentalItem(new Rental(104, cc.findClient("123456789"), cc.findVehicle("XNA1207"), new Date("6/5/2019"), new Date("6/14/2019"), 2250)));
  22. rentals.insert(new RentalItem(new Rental(105, cc.findClient("987654321"), cc.findVehicle("XNA1208"), new Date("6/7/2019"), new Date("6/15/2019"), 2400)));
  23. rentals.insert(new RentalItem(new Rental(106, cc.findClient("741258963"), cc.findVehicle("XNK5544"), new Date("6/5/2019"), new Date("6/15/2019"), 450)));
  24. rentals.insert(new RentalItem(new Rental(107, cc.findClient("258963147"), cc.findVehicle("XNM1345"), new Date("8/5/2019"), new Date("8/15/2019"), 800)));
  25.  
  26. /* using a constructor i called the method searchForRental from an other class into my main class. The searchForRental method , basically prints out the Rental according to the input variables that the user wrote.*/
  27. public Rental findRentals(String rNum, String afm, Date rentDate, Date retDate) {
  28. Rental rental = corporation.searchForRental(rNum, afm, rentDate, retDate);
  29. if(rental == null) {
  30. System.out.println("Rental not Found.");
  31. }else {
  32. rental.print();
  33. }
  34. return rental;
  35. }
  36.  
  37. public Rental searchForRental(String rNum, String afm, Date rentDate, Date retDate) {
  38. /* Here is the problem */
  39. Why does the Exception thread comes here;
  40. And, what does NullPointerException means?
  41. I thought the problem was that the input variables weren't initialized and the enviroment automatically changed them to null???
  42.  
  43. RentalItem rItem = (RentalItem)rentals.search(rNum, afm, rentDate, retDate); /* This is where the thread error begins*/
  44. if(rItem != null) {
  45. return (Rental)rItem.getData();
  46. }else {
  47. return null;
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement