Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String rNum1;
- String afm1;
- Date rentDate, retDate;
- rNum1 = reader.readString("Vehicle Registration Number: ");
- afm1 = reader.readString("Client AFM: ");
- rentDate = reader.readDate("Rent Date: ");
- retDate = reader.readDate("Return Date: ");
- /* Using the object cc of a constructor i call the method findRentals that takes the input variables of the user.*/
- cc.findRentals(rNum1, afm1, rentDate, retDate);
- /* Method findRentals */
- public Rental findRentals(String rNum, String afm, Date rentDate, Date retDate) {
- /* I initialized data into the object rental */
- rentals.insert(new RentalItem(new Rental(100, cc.findClient("123456789"), cc.findVehicle("XNK5544"), new Date("3/4/2019"), new Date("22/4/2019"), 950)));
- rentals.insert(new RentalItem(new Rental(101, cc.findClient("987456321"), cc.findVehicle("XNA1204"), new Date("4/5/2019"), new Date("4/8/2019"), 210)));
- rentals.insert(new RentalItem(new Rental(102, cc.findClient("741258963"), cc.findVehicle("XNO1706"), new Date("6/5/2019"), new Date("6/15/2019"), 405)));
- rentals.insert(new RentalItem(new Rental(103, cc.findClient("258963147"), cc.findVehicle("XNX9901"), new Date("6/5/2019"), new Date("6/15/2019"), 240)));
- rentals.insert(new RentalItem(new Rental(104, cc.findClient("123456789"), cc.findVehicle("XNA1207"), new Date("6/5/2019"), new Date("6/14/2019"), 2250)));
- rentals.insert(new RentalItem(new Rental(105, cc.findClient("987654321"), cc.findVehicle("XNA1208"), new Date("6/7/2019"), new Date("6/15/2019"), 2400)));
- rentals.insert(new RentalItem(new Rental(106, cc.findClient("741258963"), cc.findVehicle("XNK5544"), new Date("6/5/2019"), new Date("6/15/2019"), 450)));
- rentals.insert(new RentalItem(new Rental(107, cc.findClient("258963147"), cc.findVehicle("XNM1345"), new Date("8/5/2019"), new Date("8/15/2019"), 800)));
- /* 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.*/
- public Rental findRentals(String rNum, String afm, Date rentDate, Date retDate) {
- Rental rental = corporation.searchForRental(rNum, afm, rentDate, retDate);
- if(rental == null) {
- System.out.println("Rental not Found.");
- }else {
- rental.print();
- }
- return rental;
- }
- public Rental searchForRental(String rNum, String afm, Date rentDate, Date retDate) {
- /* Here is the problem */
- Why does the Exception thread comes here;
- And, what does NullPointerException means?
- I thought the problem was that the input variables weren't initialized and the enviroment automatically changed them to null???
- RentalItem rItem = (RentalItem)rentals.search(rNum, afm, rentDate, retDate); /* This is where the thread error begins*/
- if(rItem != null) {
- return (Rental)rItem.getData();
- }else {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement