Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Rates { private CarRates currentCarRates; private SUVRates currentSUVRates; private TruckRates currentTruckRates; // Constructor public Rates(){ // sets each set of rates to current

public class Rates { private CarRates currentCarRates; private SUVRates currentSUVRates; private TruckRates currentTruckRates; // Constructor public Rates(){ // sets each set of rates to current rates: daily, weekly, monthly, // daily per mile charge, and optional daily insurance rate currentCarRates = new CarRates(24.95, 149.95, 514.95, 0.15, 14.95); currentSUVRates = new SUVRates(29.95, 189.95, 679.95, 0.15, 14.95); currentTruckRates = new TruckRates(34.95, 224.95, 797.95, 0.26, 22.95); } // setters and getters public CarRates getCarRates(){ return currentCarRates; } public SUVRates getSUVRates(){ return currentSUVRates; } public TruckRates getTruckRates(){ return currentTruckRates; } public void setCarRates(CarRates r){ currentCarRates = r; } public void setSUVRates(SUVRates r){ currentSUVRates = r; } public void setTruckRates(TruckRates r){ currentTruckRates = r; } // cost calculation methods public double calcEstimatedCost(int vehicleType, String estRentalPeriod, int estNumMiles, Boolean dailyInsur, boolean primeCustomer) throws InvalidRentalPeriodFormatException { // calculates rental cost for estimated time period to use, estimated // number of miles driven, whether daily insurance desired, and // whether a prime customer (prime customers get 100 free miles per rental) VehicleRates v_rates = null; double charge; // retrieve current rates for vehicle type switch(vehicleType){ case 1: v_rates = currentCarRates; break; case 2: v_rates = currentSUVRates; break; case 3: v_rates = currentTruckRates; break; } // extract time period from (estimated) rental period string int time_period = Vehicle_Utilities.timePeriod(estRentalPeriod); // calc basic rental charge if(Vehicle_Utilities.dailyRate(estRentalPeriod)) charge = v_rates.getDailyRate() * time_period; else if(Vehicle_Utilities.weeklyRate(estRentalPeriod)) charge = v_rates.getWeeklyRate() * time_period; else if(Vehicle_Utilities.monthlyRate(estRentalPeriod)) charge = v_rates.getMonthlyRate() * time_period; else throw new InvalidRentalPeriodFormatException(); // include estimated mileage charge charge = charge + estNumMiles * v_rates.getPerMileCharge(); return charge; } public double calcActualCost(VehicleRates v_rates, int numDaysUsed, int numMilesDriven, Boolean dailyInsur, boolean primeCustomer){ // calculates rental costs for provided rental rates, number of days used, // number of miles driven, whether daily insurance was selected, and // whether a prime customer (prime customers get 100 free miles each rental). double charge; // construct formatted rental period string for numDaysUsed String rentalPeriodStr = Vehicle_Utilities.constructRentalPeriodStr(numDaysUsed); // calc basic charge based on numDayUsed only charge = calcBasicCharge(v_rates,rentalPeriodStr); // add mileage charge charge = charge + calcMileageCharge(numMilesDriven, v_rates, primeCustomer); charge = charge + calcDailyInsurCharge(numDaysUsed, v_rates); return charge; } // private methods private double calcBasicCharge(VehicleRates v_rates, String rentalPeriodStr) throws InvalidRentalPeriodFormatException{ // returns the basic charge based on the number of days used only. double basic_charge; int time_period = Vehicle_Utilities.timePeriod(rentalPeriodStr); if(Vehicle_Utilities.dailyRate(rentalPeriodStr)) basic_charge = v_rates.getDailyRate() * time_period; else if(Vehicle_Utilities.weeklyRate(rentalPeriodStr)) basic_charge = v_rates.getWeeklyRate() * time_period; else if(Vehicle_Utilities.monthlyRate(rentalPeriodStr)) basic_charge = v_rates.getMonthlyRate() * time_period; else throw new InvalidRentalPeriodFormatException(); return basic_charge; } private double calcMileageCharge(int numMiles, VehicleRates v_rates, boolean primeCustomer){ // returns mileage charge based on provided numMiles and v_rates. // if prime customer, mileage is reduced by 100 miles. double mileage_charge = 0; if(primeCustomer) numMiles = numMiles - 100; if(numMiles > 0){ mileage_charge = numMiles * v_rates.getPerMileCharge(); } return mileage_charge; } private double calcDailyInsurCharge(int numDays, VehicleRates v_rates){ // returns daily insurance charge based on provided numDaysUsed and v_rates. double insur_charge = 0; insur_charge = numDays * v_rates.getDailyInsurCharge(); return insur_charge; } public class Reservation { private String acctNum; // 5-digit account numbers private String companyName; private String rentalPeriod; // e.g., "D4" (four days), "W2" (two weeks), // "M1" (one month) private boolean insuranceSelected; public Reservation(String acctNum, String companyName, String rentalPeriod, boolean insuranceSelected){ this.acctNum = acctNum; this.rentalPeriod = rentalPeriod; this.insuranceSelected = insuranceSelected; } public String getAcctNum(){ return acctNum; } public String rentalPeriod(){ return rentalPeriod; } public boolean insuranceSelected(){ return insuranceSelected; } }

public class Accounts { private Account[] accounts; private int current_acct; // for iterator methods public Accounts(){ accounts = new Account[10]; // assume no more than 10 corporate accounts initArray(); // init accounts to all nulls current_acct = 0; // start iteration at first account } public void add(Account acct) throws NoAvailVehicleSpaceException { accounts[nextAvailIndex()] = acct; } public Account getAcctount(String acct_num) throws AccountNotFoundException { int i = 0; boolean found = false; while(!found && i < 25 && accounts[i] != null){ if (accounts[i].getAcctNum().equals(acct_num)) found = true; else i = i + 1; } if(found) return accounts[i]; throw new VinNotFoundException(); // if not found } // --- iterator methods public void reset(){ current_acct = 0; } public boolean hasNext(){ return current_acct < 25 && accounts[current_acct] != null; } public Account getNext(){ if(!hasNext()) throw new NoMoreAccontsException(); Account return_acct = accounts[current_acct]; current_acct = current_acct + 1; return return_acct; // the above three lines can be replaced with: // return accounts[current_acct++] // which increments current_acct AFTER used as index value } // --- private methods private void initArray(){ for(int i = 0; i < 10; i++){ accounts[i] = null; } } private int nextAvailIndex() throws NoAvailAccountSpaceException { int i = 0; boolean found_null = false; while(i < 10){ if (accounts[i] == null) return i; i = i + 1; } throw new NoAvailAccountSpaceException(); } }

public class Transactions { int currTransaction; private final int NUM_TRANSACTIONS = 100; private Transaction[] transactions; //contstructor public Transactions() { transactions = new Transaction[NUM_TRANSACTIONS]; currTransaction = 0; } //iterator methods public void reset() { currTransaction= 0; } public boolean hasNext() { if(currTransaction < NUM_TRANSACTIONS- 1 && transactions[currTransaction] != null) return true; else return false; } public Transaction getNextTransaction(String transactions) { Transaction next_transaction = transactions[currTransaction]; currTransaction= currTransaction + 1; return next_transaction; } //general methods public void add(Transaction t) { transactions[3] = t; } public Transaction getTransaction(String acct_num)throws AcctNumNotFoundException { int i = 0; boolean found = false; while(i < transactions.length && !found) { if(transactions[i].equals(acct_num)) found = true; else i = i + 1; } if(!found) throw new AcctNumNotFoundException(); return transactions[i]; } }

The system interface should be implemented as a class with all static methods. Thus, an object instance of this class is not created. These methods provide all of the functionality that each of the user interfaces need. This is accomplished by having one method that is called for each use case. These are the only methods that the user interfaces directly call. Each method of the System Interface class returns an array of strings. Thus, the user interfaces need only display the arrays of strings that are returned to it. Each string in the array is meant to be displayed as a separate line on the screen. The set of methods needed are given in the UML diagram below. The system interface will be defined with a set of static (private) variables, of types Rates, Vehicles, Accounts and Transactions. These variables will be assigned to the four corresponding aggregation objects in the system. public class SystemInterface { // variables set to aggregation objects private static Rates agency_rates; private static Vehicles agency_vehicles; private static Accounts accounts; private static Transactions transactions_history; // used to set aggregation objects public static void initSystemInterface(Rates r, Vehicles v, Accounts a, Transactions t) { agency_rates = r; agency_vehicles = v; accounts = a; transactions_history = t; } // Each of the following methods returns an array of strings to be displayed by the user interface. // Note that methods makeReserv, cancelReservation, and addAccount return the information // submitted as a means of confirming the requested action. public static String[] addAccount(Account acct_info) { ... } public static String[] getAccount(String acct_num) { ... } public static String[] getAllAccounts() { ... } public static String[] getCarRates() { ... } public static String[] getSUVRates() { ... } public static String[] getTruckRates() { ... } public static String[] getAvailCars() { ... } public static String[] getAvailSUVs() { ... } public static String[] getAvailTrucks() { ... } public static String[] getAllVehicles() { ... } public static String[] estimatedRentalCost(RentalDetails details) { ... } public static String[] makeReservation(ReservationDetails details) { ... } public static String[] getReservation(String vin) { ... } public static String[] getAllReservations() { ... } public static String[] cancelReservation(String vin) { ... } public static String[] processReturnedVehicle(String vin) { ... } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

List some differences between R and Python.

Answered: 1 week ago

Question

Proficiency with Microsoft Word, Excel, PowerPoint

Answered: 1 week ago