This code will be used for your finals. It consists of the four classes shown in the class diagram below. The DBase class uses an ArrayList of Customer objects to represent the customers. It has methods to find out customers who owe more than £50, and those whose payments are due in the next week. ```mermaid classDiagram Exception <|-- CustomerException Customer -- CustomerException DBase -- Customer class Customer{ -String surname -String forename -int balance -LocalDate due +String toString() +String getSurname() +void setSurname(String surname) +String getForename() +void setForename(String forename) +int getBalance() + void setBalance(int balance) +LocalDate getDue() + void setDue(String due) } class DBase{ -ArrayList customers +Arraylist readCustomersFromFile() +Arraylist printCustomers() +Arraylist getBalanceOver50() +ArrayList getDueNextWeek() void AddCustomer(Customer customer) } class CustomerException{ CustomerException(String s) } ``` # Meet the Code ## Look at the MockSkeleton Package 1. How many classes are there in the code? 2. What is the purpose of each class? 3. Look at the signature of the class CustomerException. What OOP concept is used here? ## Look at the MockSkeleton Class 1. Name a global variable used in this class 2. Explain the difference between a local variable and a global variable 3. State one reason why it's good practice to use local variables 4. Look at the constructor for MockSkeleton. What does it do? 5. The optionMenu() subroutine uses a switch statement. What are the advantages of this over multiple if statements? ## Look at the DBase Class 1. What type is the global variable customers? 2. Look at the user defined subroutine readCustomersFromFile(). What is the return type? What is the type of the parameter? 3. What is the purpose of the three catch statements in the subroutine readCustomersFromFile() 4. Look at line 31: Scanner scan = new Scanner(new File(filename)).useDelimiter(","); What is the purpose of the useDelimiter() method? ## Look at the Customer Class 1. How does this class demonstrate the OOP concept of encapsulation? 2. Why has balance been stored as an int and not a double? 3. Look at the setDue method. Why does this throw a CustomerException? 4. Explain the purpose of the regular expression in the select statement. # Exercise 1: Saving Data ## Look at the MockSkeleton Class Currently the program will only read customers from a file. You are going to add functionality to allow customers to be saved 1. Add a user defined subroutine writeFile(). This subroutine will prompt the user for a file name. If none is given, it will use the default "customers.txt". The subroutine will then write the customer details to the file. 2. Update the user defined subroutine optionMenu() to include the option "6 - Save customers to file." 3. Test your subroutines by running the program, adding a new customer and then saving the customers. Include a screenshot of the update text file. # Exercise 2: New Queries ## Look at the DBase Class There are currently two queries available, getBalanceOver50() and getDueNextWeek(). You are going to add new queries 1. Add user defined subroutine to the DBase class that will return all customers with a balance of between 30 and 50 pounds 2. Add an option "8 - Find Balances between £30 and £50." to MockSkeleton to call the query. 3. Test your code. Screenshot your results. 4. What would be a better set of test data to check your query is working correctly? 5. Add a user defined subroutine to the DBase class that will return all those people with overdue balances. 6. Add an option "9 - Overdue Balances" to MockSkeleton to call the query. 7. Test your subroutine # Exercise 3: Exception Handling ## Look at the Customer Class You are going to add validation checks and exception handling to the setter methods. 1. What are setter methods? 2. Add exception handling to the setForename() method so that only characters A-Za-z are allowed, others are rejected. All forenames must be < 50 characters. 3. Add exception handling to the setSurname() method so that only characters A-Za-z and - are allowed. All surnames must be < 50 characters. 4. Add exception handling to setBalance() Only numbers > 0 are allowed. 5. Write a set of test data to test your exception handling. ![[Customer.java]]![[CustomerException.java]]![[DBase.java]]![[MockSkeleton.java]]![[customers.txt]]