Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Stephan Garland
- Date:03DEC2014
- Project: UseCarRental - Takes user input, and creates the correct object
- */
- import java.util.Scanner;
- public class UseCarRental extends CarRental
- {
- public static void main(String[] args)
- {
- CarRental rentalCar = new CarRental();
- LuxuryCarRental luxuryRentalCar = new LuxuryCarRental();
- String name, carSize, zip;
- int rentalLength;
- Scanner keyboard = new Scanner(System.in);
- System.out.println("Welcome to U-Rents! I need some information about your rental: ");
- System.out.println("Name: ");
- name = keyboard.nextLine(); // Need nextLine() in case First and Last names are used
- System.out.println("ZIP code: ");
- zip = keyboard.next();
- while (zip.length() < 5) // Reality check
- {
- System.out.println("Sorry, please enter a 5-digit ZIP code: ");
- zip = keyboard.next();
- }
- System.out.println("Car Size - [E]conomy, [M]idsize, [F]ullsize, or [L] Luxury");
- carSize = keyboard.next();
- System.out.println("Rental length, in days: ");
- rentalLength = keyboard.nextInt();
- rentalCar.setName(name);
- rentalCar.setZip(zip);
- rentalCar.setCarSize(carSize);
- rentalCar.setRentalLength(rentalLength);
- if (carSize.toUpperCase().charAt(0) == 'L') // Send all the below to LuxuryCarRental if necessary
- {
- luxuryRentalCar.setName(name);
- luxuryRentalCar.setCarSize(carSize);
- luxuryRentalCar.setRentalLength(rentalLength);
- luxuryRentalCar.setZip(zip);
- luxuryRentalCar.display();
- }
- else rentalCar.display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement