Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Stephan Garland
- Date:03DEC2014
- Project: CarRental - holds data fields for renting a car
- */
- import java.math.BigDecimal;
- public class CarRental
- {
- protected String name, carSize, zip;
- protected int rentalLength;
- protected double dailyFee, totalFee;
- public String getName()
- {
- return name;
- }
- public void setName(String name)
- {
- this.name = name;
- }
- public String getCarSize()
- {
- return carSize;
- }
- public void setCarSize(String carSize)
- {
- this.carSize = carSize;
- }
- public String getZip()
- {
- return zip;
- }
- public void setZip(String zip)
- {
- this.zip = zip;
- }
- public int getRentalLength()
- {
- return rentalLength;
- }
- public void setRentalLength(int rentalLength)
- {
- this.rentalLength = rentalLength;
- }
- public static void main(String[] args)
- {
- }
- String carSizeSwitcher()
- {
- carSize = carSize.toUpperCase(); // Allows for no case checking in switch, and eliminates Turkish locale bug
- char carSizeSwitch = carSize.charAt(0); // Greatly reduces errors due to mis-spellings
- switch(carSizeSwitch)
- {
- case 'E' :
- carSize = "Economy";
- dailyFee = 29.99;
- break;
- case 'M' :
- carSize = "Midsize";
- dailyFee = 38.99;
- break;
- case 'F' :
- carSize = "Fullsize";
- dailyFee = 43.50;
- break;
- default :
- System.out.println("Invalid selection");
- }
- return carSize; // Gets used later in this display()
- }
- // These two are used in the other files, so money prints nicely
- public BigDecimal getDailyFee()
- {
- BigDecimal dispDailyFee = new BigDecimal(dailyFee);
- dispDailyFee = dispDailyFee.setScale(2, BigDecimal.ROUND_HALF_UP);
- return dispDailyFee;
- }
- public BigDecimal getTotalFee()
- {
- BigDecimal dispTotalFee = new BigDecimal(totalFee);
- dispTotalFee = dispTotalFee.setScale(2, BigDecimal.ROUND_HALF_UP);
- return dispTotalFee;
- }
- void display()
- {
- carSizeSwitcher();
- totalFee = dailyFee * getRentalLength();
- System.out.println("\nRental summary");
- System.out.println("\n" + getName());
- System.out.println("ZIP code " + getZip());
- System.out.println(carSizeSwitcher() +
- " at $" + getDailyFee() +
- " for " + getRentalLength() + " days" +
- " for a total of $" + getTotalFee());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement