Question: 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
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 zipCode) 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.
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 Customers 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.
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 Accounts 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.
Class Project2Driver: The Project2Driver class should contain the following methods: public static Account[] readAccountsFromFile(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 writeAccountsToFile(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 writeAccountsToFile() methods here.
JUnit Tester Classes: Create three test classes, one class for each of the custom classes listed above, to write JUnit tests for. Create a class named AddressTester to test the Address class. Create a class named CustomerTester to test the Customer class. Create a class named AccountTester to test the Account class. In each tester class, you have to test all the methods of the classes including constructors, getters and setters, and the remaining public interface methods. You can create multiple objects of the class for testing purposes. When you test, you need to make sure you think about all possible scenarios (edge cases) for each individual method.
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;
JavaDoc Style Comments: You are required to make JavaDoc comments for all classes (including the tester classes) and methods including parameters and return descriptions.
Important Note: Please make sure the file names are correct and the code is well commented!
Rubric:
| Task | Grade |
| Address | |
| Correctly implement constructors | 3 |
| Correctly implement getters and setters | 5 |
| Correctly implement equals() method | 3 |
| Correctly implement toString() method | 3 |
| Customer | |
| Correctly implement constructors | 3 |
| Correctly implement getters and setters | 4 |
| Correctly implement equals() method | 3 |
| Correctly implement toString() method | 3 |
| Account | |
| Correctly implement constructors | 3 |
| Correctly implement getters and setters | 2 |
| Correctly implement equals() method | 3 |
| Correctly implement toString() method | 3 |
| Correctly implement deposit() method | 3 |
| Correctly implement withdraw() method | 3 |
| Project2Driver | |
| Correctly implement readAccountsFromFile() method | 9 |
| Correctly implement writeAccountsToFile() method | 9 |
| Use main() method to test readAccountsFromFile() and writeAccountsToFile() methods | 6 |
| Tester Classes | |
| Test constructors | 9 |
| Test getters and setters | 11 |
| Test equals() and toString() methods | 6 |
| Test deposit() and withdraw() methods | 6 |
| JavaDoc | |
| JavaDoc style comments for each method and class present (will only lose points if not present) | 0 (-10) |
| Total | 10 |

Here's what I have so far:











accounts - Notepad File Edit Format View Help 101, 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, 90587, 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 28 1 public class Address {l 2 private int streetNumber; 3 private String streetName; 4 private String city; 5 private String state; 6 private String zipCode; 7 se public Address({ 9 this.streetName = 10 this.city 11 this.state = ""; 12 this.zipCode 13 this.streetNumber = ; 14 } 15 160 public Address(int streetNumber, String streetName, String city,String state, 17 String zipCode) { 18 this.streetName = streetName; 19 this.city city; 20 this.state = state; 21 this.zipCode = zipCode; 22 this.streetNumber = streetNumber; 23 } 24 25 public Address(Address address) { 26 streetNumber = address.streetNumber; 27 streetName = address.streetName; city = address.city; 29 state = address.state; 30 zipCode address.zipCode; 31 } 32 33e public boolean equals(object o){ 34 if(o instanceof Address ){ 35 if(this.streetNumber == ((Address) o).streetNumber && 36 this.streetName == ((Address) o).streetName && 37 this.city ((Address) o).city && this.state ((Address) o).state && this.zipCode ((Address) o).zipCode || this == 0){ 39 return true; 40 } 41 } 42 43 return false; } 45 46 public String toString(){ 47 return streetNumber+" "+streetName+", "+city+", "+state+", "+zipcode; 48 } 49 50e public void setcity(String city) { 51 this.city = city; 52 } 53 540 public void setState(String state) { 55 this.state = state; 56 } 57 580 public void setStreetName(String streetName) { 59 this.streetName = streetName; == == 38 44 60 61 } 620 public void setStreetNumber(int streetNumber) { this.streetNumber = streetNumber; } public void setZipCode(String zipcode) { this.zipCode = zipCode; } public int getStreetNumber() { return streetNumber; } 63 64 65 660 67 68 69 700 71 72 73 740 75 76 77 780 79 80 81 820 83 public String getCity() { return city; } public String getState() { return state; } public String getStreetName() { return streetName; } 84 85 860 87 public String getZipCode() { return zipcode; } 88 89} 10 import static oca Junit. Assert-*;|| 2 3 import java, security InvalidParameterException; 4 import org.junit. Test; 5 6 class Address Tester { 7 se @Test 9 void testEquals() { 10 } 11 12e @Test 13 void testToString() { 14 } 15 16e @Test 17 void setCity() { 18 } 19 20e @Test 21 void setstate() { 22 } 23 240 @Test 25 void setStreetName() { 26 } 27 28e @Test 29 void setStreetNumber() { 30 } 31 32e @Test 33 void setZipCode() { 34 } 35 360 @Test 37 void getStreetNumber() { 38 } 39 400 @Test 41 void getCity() { 42 } 43 44e @Test 45 void getState() { 46 } 47 480 @Test 49 void getStreetName() { 50 } 51 52e @Test 53 void getZipCode() { 54 } 55 } 1 public class Customer {l 2 static int staticid = 1000; 3 private int id; 4 private String name; 5 private Address address; private String ssn; 7 se public Customer(){ 9 this.id = Integer.parseInt(null); 10 this.address = null; 11 this.name = 12 this.ssn = 13 } 14 150 public Customer (String name, 2, Address, address,String ssn) { 16 this.name = name; 17 this.address = address; 18 this.ssn = ssn; 19 this.staticid++; 20 id = staticid; 21 } 22 230 public Customer(Customer customer) { name = customer.name; 25 address = customer address; 26 ssn = customer.ssn; 27 } 28 290 public boolean equals(object o){ 30 if(o instanceof Customer){ 31 if(((Customer) o).address.equals(this.address) && 32 (Customer) o).name == this.name && 33 (Customer) o).ssn == this.ssn || 0 this) { 34 return true; 35 } 36 } 37 38 return false; 39 } 40 410 public String toString(){ 42 return this.id+ + name + + address.toString()+", "+s5n; 43 } 44 345 public int getId() { 46 return id; 47 } 24 48 public Address getAddress() { return address; } 490 50 51 52 530 54 55 56 5570 58 59 public String getName() { return name; } public String getssn() { return ssn; } public void setAddress(Address address) { this.address = address; } 60 9x616 9x62 63 64 65e 66 67 68 69e 70 71 72 } public void setName(String name) { this.name = name; } public void setssn(String ssn) { this.ssn = ssn; } 10 import static org junit Assert. * ;|| 2 3 import java, security InvalidParameterException 4 import org.junit. Test; 5 6 class CustomerTester { 7 se 9 @Test void testEquals() { } 10 @Test void testToString() { } @Test void getId() { } 11 12e 13 14 15 160 17 18 19 200 21 22 23 240 25 26 27 28e 29 @Test void getAddress() { } @Test void getName() { } @Test void getssn() { } 30 @Test void setAddress() { } 31 32e 33 34 35 360 37 38 39 400 41 42 43 } @Test void setName() { } @Test void setssn() { } 1 public class Account {l 2 int id; 3 static int staticid = 1000; 4 private Customer customer; 5 private double balance; public Account (Customer customer) { this.customer = customer; this.balance = 0; this.id = 1000; } public Account (Customer customer, double balance) { this.customer = customer; this.balance = balance; staticid++; this.id = staticid; } 7 8 9 10 11 12 130 14 15 16 17 18 19 200 21 22 23 24 250 26 27 28 290 30 31 32 33 public Account (Account account) { this.customer = account.customer; this.balance = account.balance; } public void deposit(double amount){ balance = balance + amount; } public boolean withdraw(double amount) { if(balance >= amount) { balance = balance - amount; return true; } return false; } 34 35 36 3370 38 339 40 41 42 43 44 45 346 $476 public boolean equals(Object 0){ if(o instanceof Account){ if(this.balance == ((Account) 0). balance && this.customer.equals(((Account) o).customer)) { return true; } } return false; } 48 public String toString({ return this.id+", "+customer.toString()+", "+balance; } public int getId() { return id; } 49 50 510 52 53 54 55e 56 357 58 590 public Customer getCustomer() { return customer; } public double getBalance() { 60 61 62 630 64 65 66 670 68 69 70 } return balance; } public void setBalance (double balance) { this.balance = balance; } public void setCustomer (Customer customer) { this.customer = customer; } 10 import static oca Junit. Assert-*;|| 2 3 import java, security InvalidParameterException; 4 import org.junit. Test; 5 6 class AccountTester { 7 8e @Test 9 void deposit() { 10 } 11 12e @Test 13 void withdraw() { 14 } 15 16e @Test 17 void testEquals() { 18 } 19 20e @Test 21 void testToString() { 22 } 23 240 @Test 25 void getId() { 26 } 27 28e @Test 29 void getCustomer() { 30 } 31 32e @Test 33 void getBalance() { 34 } 35 360 @Test 37 void setBalance() { 38 } 39 400 @Test 41 void setCustomer() { 42 } 43 } 10 import java.io.File;|| 2 import java.io.FileNotFoundException; 3 import java.io.FileWriter; 4 import java.io.IOException; 5 import java.util.Scanner; 6 8 7 public class Project2Driver { public static Account[] readAccountsFromFile(String fileName) throws FileNotFoundException { File file = new File(fileName); Scanner scanner = new Scanner(file); 11 Account accounts[] = new Account [10]; 9 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 280 29 30 31 32 33 34 itt; int i=0; while(scanner.hasNextLine()) { String account = scanner.nextLine(); String[] account_info = account.split(", "); String[] streetNo_street = account_info[3].split(" "); Address address = new Address (Integer.parseInt(streetNo_street[@]), streetNo_street[1] + + streetNo_street[2], account_info[4], account_info[5], account_info[6]); Customer customer = new Customer (account_info[2], address, account_info[7]); accounts[i] = new Account(customer,Double.parseDouble(account_info[8])); } return accounts; } public static boolean writeAccountsToFile(Account[] accounts,String filename) throws IOException { File file = new File(filename); 35 36 37 38 39 if(!file.exists() return false; else{ FileWriter writer = new FileWriter(filename, true);} for(int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
