Question: java accounts.txt file: Introduction: In this project, we will solidify our class making abilities. Specifically, we will create multiple classes, use files to store and
java





accounts.txt file: 
Introduction: In this project, we will solidify our class making abilities. Specifically, we will create multiple classes, use files to store and retrieve data, write JavaDoc documentation, and test our code with JUnit tests. To begin, create a project in Eclipse named Project2. Now, create a class that follows the requirements for each class listed below. Class Address: Create a class named Address that has the following private Instance Properties: int streetNumber An integer variable that holds the street number of the address. . String streetName A String object that holds the street name. . String city A String object that holds the name of the city. String state - A String object that holds the two letter abbreviation of the state. . String zipCode A string object that holds the five-digit ZIP code. The Address class should contain the following methods: public Address() - The default (or empty) constructor that initializes the instance properties to the default values (all Strings to and the int to 0). public Address(int streetNumber, String streetName, String city, String state, String zip Code) - The workhorse constructor that initializes the instance properties with the input parameters. public Address(Address address) The copy constructor that initializes the instance properties using the values of another Addresss instance properties. public boolean equals(Object o) - Override the default object class equals(). This method should return true if the Object parameter is an instance of Address and if the two Addresses have the same street number, street name, city, state, and ZIP code and false, otherwise. . public String toString() - Override the default object class toString(). This method should return a string representation of the Address object that includes the street number, street name, city, state, and ZIP code. An example return call of this method is as follows. 2000 Main Street, Santa Monica, FL, 30309. A set of getters and setters for all Instance Properties. Look at the Week 3 and 4 Lecture Code for examples. Class Customer: Create a class named Customer that has the following private Instance Properties: int id An integer variable that holds the ID of the customer. This ID is autogenerated and starts from 1000. The very first customer object will have an ID of 1000. Each customer object after will get an ID incremented by 1. For example, the 2nd and 3rd customer objects are going to have an ID of 1001 and 1002, respectively. String name - A String object that holds the name of the customer. Address address An Address object that holds the address of the customer. String ssn A String object that holds the social security number of the customer. The format of the ssn is of XXX-XX-XXXX. For example, "123-45-6789". The Customer class should contain the following methods: public Customer() - The default (or empty) constructor that initializes the instance properties to the default values (all Strings to "", initializes the id field, and Address to null). Recall that the id field is auto generated. public Customer(String name, Address address, String ssn) - The workhorse constructor that initializes the instance properties with the input parameters. Recall that the id field is auto generated public Customer(Customer customer) - The copy constructor that initializes the instance properties using the values of another Customer's instance properties. Recall that the id field is auto generated and should not be copied from the customer in the parameter. public boolean equals(Object o) - Override the default object class equals(). This method should return true if the Object parameter is an instance of Customer and if the two Customers have the same name, address, and SSN and false, otherwise. public String toString() - Override the default object class toString(). This method should return a string representation of the Customer object that includes the ID, name, address, and SSN. An example return call of this method is as follows. 1003, John Connor, 2000 Main Street, Santa Monica, FL, 30309, 123-45-6789". A set of getters and setters for all Instance Properties EXCEPT the id field. We ONLY want a getter as the id field is auto generated so we do not want to be able to set it. Look at the Week 3 and 4 Lecture Code for examples. Class Account: Create a class named Account that has the following private Instance Properties: int id An integer variable that holds the ID of the account. This ID is autogenerated and starts from 1000. The very first account object will have an ID of 1000. Each account object after will get an ID incremented by 10. For example, the 2nd and 3rd account objects are going to have an ID of 1010 and 1020, respectively. Customer customer - A Customer object that holds the information of the account holder. double balance - A double variable that holds the current balance of the account. The balance cannot be a negative number. The Account class should contain the following methods: . public Account(Customer customer) - A partial constructor that initializes the customer instance property, generates and ID for the id field, and initializes the balance to 0. . public Account(Customer customer, double balance) - The workhorse constructor that initializes the instance properties with the input parameters. Recall that the id field is auto generated. . public Account(Account account) The copy constructor that initializes the instance properties using the values of another Account's instance properties. Recall that the id field is auto generated and should not be copied from the customer in the parameter. . public void deposit(double amount) - This method deposits money to the account. That is, it adds the amount from the parameter to the balance variable. public boolean withdraw(double amount) - This method withdraws money from the account if there is enough in the balance. That is, deduct the amount from the parameter from the balance if the balance is greater than or equal to the amount. Returns true if successful and false, otherwise. public boolean equals(Object o) - Override the default object class equals(). This method should return true if the Object parameter is an instance of Account and if the two Accounts have the same id and customer and false, otherwise. public String toString() - Override the default object class toString(). This method should return a string representation of the Account object that includes the ID, customer information, and balance. An example return call of this method is as follows. 1030, 1003, John Connor, 2000 Main Street, Santa Monica, FL, 30309, 123-45-6789, 9099.05. The first number in the String is the account ID, the second number is the customer ID, and the last number if the balance in the account. . A set of getters and setters for all Instance Properties EXCEPT the id field. We ONLY want a getter as the id field is auto generated so we do not want to be able to set it. Look at the Week 3 and 4 Lecture Code for examples. Class Project2Driver: The Project2Driver class should contain the following methods: public static Account[] read AccountsFromFile(String fileName) - This method reads in all accounts information from the file name "accounts.txt" and returns an array of Account objects. The method returns null if there is no information in the file. We assume the file contains information for 10 accounts. The account information is stored as a String in the text file. Each line has the information of a single account in the following format. 1030, 1003, John Connor, 2000 Main Street, Santa Monica, FL, 30309, 123-45-6789, 9099.05. Remember that the account and customer ids are auto generated. You should discard the first two ids when you create new Account objects. Hint: you can use the split method from the String class to separate the single account information using commas as the split delimiter. public static boolean write AccountsToFile(Account[] accounts, String filename) This method writes the information from the accounts array to the file as text. Returns false if it fails to write to the file and true, otherwise. public static void main(String[] args) This is the main method that will run your program. You are to test the readAccountsFromFile() and write AccountsToFile() methods here. Testing ID Auto Generation: You must also test the auto generation of the ID for the Account and Customer classes. Please make sure you use a static variable to auto generate IDs. When you use a static variable for the Account and Customer classes, respectively, you need to give them package level access (no private or public keywords). The declaration should look like this: static int staticID = 1000; Now, when you are going to write your JUnit tests for the Customer and Account classes, you will be able to directly access these static variables. One important thing to remember is that static variables retain their values between JUnit test cases. SO, you must manually reset the static variables for each test method by doing the following: Customer.staticID = 1000; Account.staticID = 1000; 1010, 1001, Sarah Williams, 2000 Main Street, Santa Monica, FL, 30309, 123-45-6789, 9099.03 1310, 1004, Alex Brown, 400 South Johnsville Road, New Lebanon, OH, 45345, 987-65-4321, 0.03 1450, 1003, Will Deaton, 523 Help Street, Seattle, WS, 73926, 861-40-8943, 4627.98 2200, 1006, Ash Brown, 600 That Street, Lexington, KY, 93658, 123-15-6789, 14.34 1990, 1007, Svetlana Kolobanova, 700 This Street, Harrisburg, PA, 01836, 143-45-6789, 13413.43 1720, 10010, Vald Putin, 800 That Other Street, Altoona, PA, 02846, 123- 45-7789, 12470.93 9850, 1002, Ben Hem, 123 Plain Road, Las Vegas, NA, 190587, 123-45-6787, 9352.65 2140, 10053, Andy Wade Williams, 678 Sulphur Springs, Huston, TX, 19472, 125-45-6789, 1347829.09 52350, 10067, John Williams, 69 Nice Road, Austin, TX, 91248, 123-45-6319, 134.3 15230, 10078, Bob Grey, 875 New Street, Columbus, OH, 49024, 123-45-6723, 0.0 Introduction: In this project, we will solidify our class making abilities. Specifically, we will create multiple classes, use files to store and retrieve data, write JavaDoc documentation, and test our code with JUnit tests. To begin, create a project in Eclipse named Project2. Now, create a class that follows the requirements for each class listed below. Class Address: Create a class named Address that has the following private Instance Properties: int streetNumber An integer variable that holds the street number of the address. . String streetName A String object that holds the street name. . String city A String object that holds the name of the city. String state - A String object that holds the two letter abbreviation of the state. . String zipCode A string object that holds the five-digit ZIP code. The Address class should contain the following methods: public Address() - The default (or empty) constructor that initializes the instance properties to the default values (all Strings to and the int to 0). public Address(int streetNumber, String streetName, String city, String state, String zip Code) - The workhorse constructor that initializes the instance properties with the input parameters. public Address(Address address) The copy constructor that initializes the instance properties using the values of another Addresss instance properties. public boolean equals(Object o) - Override the default object class equals(). This method should return true if the Object parameter is an instance of Address and if the two Addresses have the same street number, street name, city, state, and ZIP code and false, otherwise. . public String toString() - Override the default object class toString(). This method should return a string representation of the Address object that includes the street number, street name, city, state, and ZIP code. An example return call of this method is as follows. 2000 Main Street, Santa Monica, FL, 30309. A set of getters and setters for all Instance Properties. Look at the Week 3 and 4 Lecture Code for examples. Class Customer: Create a class named Customer that has the following private Instance Properties: int id An integer variable that holds the ID of the customer. This ID is autogenerated and starts from 1000. The very first customer object will have an ID of 1000. Each customer object after will get an ID incremented by 1. For example, the 2nd and 3rd customer objects are going to have an ID of 1001 and 1002, respectively. String name - A String object that holds the name of the customer. Address address An Address object that holds the address of the customer. String ssn A String object that holds the social security number of the customer. The format of the ssn is of XXX-XX-XXXX. For example, "123-45-6789". The Customer class should contain the following methods: public Customer() - The default (or empty) constructor that initializes the instance properties to the default values (all Strings to "", initializes the id field, and Address to null). Recall that the id field is auto generated. public Customer(String name, Address address, String ssn) - The workhorse constructor that initializes the instance properties with the input parameters. Recall that the id field is auto generated public Customer(Customer customer) - The copy constructor that initializes the instance properties using the values of another Customer's instance properties. Recall that the id field is auto generated and should not be copied from the customer in the parameter. public boolean equals(Object o) - Override the default object class equals(). This method should return true if the Object parameter is an instance of Customer and if the two Customers have the same name, address, and SSN and false, otherwise. public String toString() - Override the default object class toString(). This method should return a string representation of the Customer object that includes the ID, name, address, and SSN. An example return call of this method is as follows. 1003, John Connor, 2000 Main Street, Santa Monica, FL, 30309, 123-45-6789". A set of getters and setters for all Instance Properties EXCEPT the id field. We ONLY want a getter as the id field is auto generated so we do not want to be able to set it. Look at the Week 3 and 4 Lecture Code for examples. Class Account: Create a class named Account that has the following private Instance Properties: int id An integer variable that holds the ID of the account. This ID is autogenerated and starts from 1000. The very first account object will have an ID of 1000. Each account object after will get an ID incremented by 10. For example, the 2nd and 3rd account objects are going to have an ID of 1010 and 1020, respectively. Customer customer - A Customer object that holds the information of the account holder. double balance - A double variable that holds the current balance of the account. The balance cannot be a negative number. The Account class should contain the following methods: . public Account(Customer customer) - A partial constructor that initializes the customer instance property, generates and ID for the id field, and initializes the balance to 0. . public Account(Customer customer, double balance) - The workhorse constructor that initializes the instance properties with the input parameters. Recall that the id field is auto generated. . public Account(Account account) The copy constructor that initializes the instance properties using the values of another Account's instance properties. Recall that the id field is auto generated and should not be copied from the customer in the parameter. . public void deposit(double amount) - This method deposits money to the account. That is, it adds the amount from the parameter to the balance variable. public boolean withdraw(double amount) - This method withdraws money from the account if there is enough in the balance. That is, deduct the amount from the parameter from the balance if the balance is greater than or equal to the amount. Returns true if successful and false, otherwise. public boolean equals(Object o) - Override the default object class equals(). This method should return true if the Object parameter is an instance of Account and if the two Accounts have the same id and customer and false, otherwise. public String toString() - Override the default object class toString(). This method should return a string representation of the Account object that includes the ID, customer information, and balance. An example return call of this method is as follows. 1030, 1003, John Connor, 2000 Main Street, Santa Monica, FL, 30309, 123-45-6789, 9099.05. The first number in the String is the account ID, the second number is the customer ID, and the last number if the balance in the account. . A set of getters and setters for all Instance Properties EXCEPT the id field. We ONLY want a getter as the id field is auto generated so we do not want to be able to set it. Look at the Week 3 and 4 Lecture Code for examples. Class Project2Driver: The Project2Driver class should contain the following methods: public static Account[] read AccountsFromFile(String fileName) - This method reads in all accounts information from the file name "accounts.txt" and returns an array of Account objects. The method returns null if there is no information in the file. We assume the file contains information for 10 accounts. The account information is stored as a String in the text file. Each line has the information of a single account in the following format. 1030, 1003, John Connor, 2000 Main Street, Santa Monica, FL, 30309, 123-45-6789, 9099.05. Remember that the account and customer ids are auto generated. You should discard the first two ids when you create new Account objects. Hint: you can use the split method from the String class to separate the single account information using commas as the split delimiter. public static boolean write AccountsToFile(Account[] accounts, String filename) This method writes the information from the accounts array to the file as text. Returns false if it fails to write to the file and true, otherwise. public static void main(String[] args) This is the main method that will run your program. You are to test the readAccountsFromFile() and write AccountsToFile() methods here. Testing ID Auto Generation: You must also test the auto generation of the ID for the Account and Customer classes. Please make sure you use a static variable to auto generate IDs. When you use a static variable for the Account and Customer classes, respectively, you need to give them package level access (no private or public keywords). The declaration should look like this: static int staticID = 1000; Now, when you are going to write your JUnit tests for the Customer and Account classes, you will be able to directly access these static variables. One important thing to remember is that static variables retain their values between JUnit test cases. SO, you must manually reset the static variables for each test method by doing the following: Customer.staticID = 1000; Account.staticID = 1000; 1010, 1001, Sarah Williams, 2000 Main Street, Santa Monica, FL, 30309, 123-45-6789, 9099.03 1310, 1004, Alex Brown, 400 South Johnsville Road, New Lebanon, OH, 45345, 987-65-4321, 0.03 1450, 1003, Will Deaton, 523 Help Street, Seattle, WS, 73926, 861-40-8943, 4627.98 2200, 1006, Ash Brown, 600 That Street, Lexington, KY, 93658, 123-15-6789, 14.34 1990, 1007, Svetlana Kolobanova, 700 This Street, Harrisburg, PA, 01836, 143-45-6789, 13413.43 1720, 10010, Vald Putin, 800 That Other Street, Altoona, PA, 02846, 123- 45-7789, 12470.93 9850, 1002, Ben Hem, 123 Plain Road, Las Vegas, NA, 190587, 123-45-6787, 9352.65 2140, 10053, Andy Wade Williams, 678 Sulphur Springs, Huston, TX, 19472, 125-45-6789, 1347829.09 52350, 10067, John Williams, 69 Nice Road, Austin, TX, 91248, 123-45-6319, 134.3 15230, 10078, Bob Grey, 875 New Street, Columbus, OH, 49024, 123-45-6723, 0.0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
