Advertisement
Stephonovich

UseCarRental.java

Dec 9th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. /*
  2. Author: Stephan Garland
  3. Date:03DEC2014
  4. Project: UseCarRental - Takes user input, and creates the correct object
  5.  */
  6.  
  7. import java.util.Scanner;
  8.  
  9. public class UseCarRental extends CarRental
  10. {
  11.            
  12.     public static void main(String[] args)
  13.     {
  14.         CarRental rentalCar = new CarRental();
  15.         LuxuryCarRental luxuryRentalCar = new LuxuryCarRental();
  16.         String name, carSize, zip;
  17.         int rentalLength;
  18.        
  19.         Scanner keyboard = new Scanner(System.in);
  20.         System.out.println("Welcome to U-Rents!  I need some information about your rental: ");
  21.         System.out.println("Name: ");
  22.         name = keyboard.nextLine(); // Need nextLine() in case First and Last names are used
  23.         System.out.println("ZIP code: ");
  24.         zip = keyboard.next();
  25.        
  26.         while (zip.length() < 5) // Reality check
  27.                 {
  28.                     System.out.println("Sorry, please enter a 5-digit ZIP code: ");
  29.                     zip = keyboard.next();
  30.                 }
  31.        
  32.         System.out.println("Car Size - [E]conomy, [M]idsize, [F]ullsize, or [L] Luxury");
  33.         carSize = keyboard.next();
  34.         System.out.println("Rental length, in days: ");
  35.         rentalLength = keyboard.nextInt();
  36.        
  37.         rentalCar.setName(name);
  38.         rentalCar.setZip(zip);
  39.         rentalCar.setCarSize(carSize);
  40.         rentalCar.setRentalLength(rentalLength);
  41.        
  42.         if (carSize.toUpperCase().charAt(0) == 'L') // Send all the below to LuxuryCarRental if necessary
  43.         {
  44.             luxuryRentalCar.setName(name);
  45.             luxuryRentalCar.setCarSize(carSize);
  46.             luxuryRentalCar.setRentalLength(rentalLength);
  47.             luxuryRentalCar.setZip(zip);
  48.             luxuryRentalCar.display();
  49.         }
  50.         else rentalCar.display();
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement