Advertisement
Stephonovich

CarRental.java

Dec 9th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. /*
  2. Author: Stephan Garland
  3. Date:03DEC2014
  4. Project: CarRental - holds data fields for renting a car
  5.  */
  6. import java.math.BigDecimal;
  7.  
  8. public class CarRental
  9. {
  10.     protected String name, carSize, zip;
  11.     protected int rentalLength;
  12.     protected double dailyFee, totalFee;
  13.    
  14.     public String getName()
  15.     {
  16.         return name;
  17.     }
  18.    
  19.     public void setName(String name)
  20.     {
  21.         this.name = name;
  22.     }
  23.    
  24.     public String getCarSize()
  25.     {
  26.        
  27.         return carSize;
  28.     }
  29.    
  30.     public void setCarSize(String carSize)
  31.     {
  32.         this.carSize = carSize;
  33.     }
  34.    
  35.     public String getZip()
  36.     {
  37.         return zip;
  38.     }
  39.    
  40.     public void setZip(String zip)
  41.     {
  42.         this.zip = zip;
  43.     }
  44.    
  45.     public int getRentalLength()
  46.     {
  47.         return rentalLength;
  48.     }
  49.    
  50.     public void setRentalLength(int rentalLength)
  51.     {
  52.         this.rentalLength = rentalLength;
  53.     }
  54.    
  55.     public static void main(String[] args)
  56.     {
  57.      
  58.     }
  59.    
  60.     String carSizeSwitcher()
  61.         {
  62.            carSize = carSize.toUpperCase(); // Allows for no case checking in switch, and eliminates Turkish locale bug
  63.            char carSizeSwitch = carSize.charAt(0); // Greatly reduces errors due to mis-spellings
  64.            switch(carSizeSwitch)
  65.             {
  66.                 case 'E' :
  67.                     carSize = "Economy";
  68.                     dailyFee = 29.99;
  69.                     break;
  70.                 case 'M' :
  71.                     carSize = "Midsize";
  72.                     dailyFee = 38.99;
  73.                     break;
  74.                 case 'F' :
  75.                     carSize = "Fullsize";
  76.                     dailyFee = 43.50;
  77.                     break;
  78.                
  79.                 default :
  80.                     System.out.println("Invalid selection");
  81.            }
  82.            return carSize; // Gets used later in this display()
  83.         }
  84.    
  85.     // These two are used in the other files, so money prints nicely
  86.     public BigDecimal getDailyFee()
  87.     {
  88.          BigDecimal dispDailyFee = new BigDecimal(dailyFee);
  89.          dispDailyFee = dispDailyFee.setScale(2, BigDecimal.ROUND_HALF_UP);
  90.          return dispDailyFee;
  91.     }
  92.    
  93.     public BigDecimal getTotalFee()
  94.     {
  95.        BigDecimal dispTotalFee = new BigDecimal(totalFee);
  96.        dispTotalFee = dispTotalFee.setScale(2, BigDecimal.ROUND_HALF_UP);
  97.        return dispTotalFee;
  98.     }
  99.    
  100.     void display()
  101.     {
  102.         carSizeSwitcher();
  103.         totalFee = dailyFee * getRentalLength();
  104.        
  105.         System.out.println("\nRental summary");
  106.         System.out.println("\n" + getName());
  107.         System.out.println("ZIP code " + getZip());
  108.         System.out.println(carSizeSwitcher() +
  109.                 " at $" + getDailyFee() +
  110.                 " for " + getRentalLength() + " days" +
  111.                 " for a total of $" + getTotalFee());
  112.     }
  113.    
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement