Description
This Assignment involves developing a Monthly Account Book program that makes use of a Linked List data structure. Your program needs to provide features that include: inserting records, removing records, modifying records, and displaying records & balance, so that the user is able to manage their expenses with it.
OBJECTIVES AND GRADING CRITERIA
The main goal of this assignment is to familiarize yourself with the Linked List data structure, and to implement the following operations: traversal, insertion, removal, and modification.
25 points
5 zyBooks Tests: automated grading test results are visible upon submission, and allow multiple opportunities to correct the organization and functionality of your code. Your highest scoring submission prior to the deadline will be recorded.
25 points
5 Hidden Tests: automated grading tests are run after the assignment’s deadline. They check for similar functionality and organizational correctness as the zyBooks Tests. But you will NOT be able to resubmit corrections for extra points, and should therefore consider and test your own code even more thoroughly.
THE RECORDNODE CLASS
1. A singly linked list comprises a collection of one-way connected nodes. For this assignment, this list represents an account book, and each node stores a single account transaction record.
LECTURE NOTES
Therefore, the first step for us is to create a class called ecordNode, each instance of which is a node in the list representing one account record. You should have the following private instance fields in this class. private int day; private double amount; private RecordNode next; These fields hold the ay on which the record occurred, the money amount of the record, as well as the reference to the net record node in the list, respectively. You also need to add necessary public accessors and mutators for these fields, so that you can access them outside the class. For a field called y, the accessor and mutator of this field should be named as gety and sety respectively, following our course style guide. You should add constructor(s) to this class to help initialize new objects, including one with the following constructor at a minimum: public RecordNode(int day, double amount). This constructor should initialize the day and amount fields based on the provided arguments, and should initialize the next field to be null.
THE ACCOUNTBOOK CLASS
2. As mentioned above, the AccountBook class is represented as a Linked List. This class must include the following fields: private RecordNode head; private RecordNode tail; private double balance; These fields hold the a reference to the head (or first element in the list), a reference to the tail (or last element in the list), and the overall balance of the account book. Upon instantiation, these fields should be initialized to null, null, and 0 respectively.
3. In your ccountook class, you should implement the following instance methods, each of which realizes and exposes a feature of your account book to the user. The signature and function description of the methods are as following:
1 2 3 4 5 6 7 8 9
/** * Insert a record node into the account book. The money amount can be either * negative, meaning the user spent money, or positive, meaning the user * received money. If in the account book there are records on the same day, you * need to insert the record after the last of them; Otherwise, you need to * insert the record between records on earlier days and those on later days. * * @param day * The day of the record to be inserted.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
* @param amount * The money amount of the record. */ public public void void insertRecord(int int day, double double amount) {} /** * Prepend a record into the account book. The day of the record should be the * same as the EARLIEST record in the book. If there haven’t been any records in * the book yet, you should show user the warning message “WARNING: Unable to * prepend a record, for no records in the account book yet.” by printing it to * the console. * * @param amount * The money amount of the record to be prepended. */ public public void void prependRecord(double double amount) {} /** * Append a record into the account book. Similar as above, the day of the * record should be the same as the LATEST record. If there haven’t no records * in the book yet, you should show user the warning message “WARNING: Unable to * append a record, for no records in the account book yet.”. * * @param amount * The money amount of the record to be appended. */ public public void void appendRecord(double double amount) {} /** * Remove a record from the account book. The two arguments identify which * record to remove. E.g., with day being 4 and seq_num being 2, the user * would like to delete the second record on the 4th day. If the number of * records on day is smaller than seq_num, you show user the warning message * “WARNING: Unable to remove a record, for not enough records on the day * specified.”. * * @param day * The day of the record to be removed. * @param seq_num * The sequence number of the record within the day of it. */ public public void void removeRecord(int int day, int int seq_num) {} /** * Modify a record in the account book. Similar as above, day and seq_num * identify which record to modify, while amount indicates the excepted money * amount of the record after modification E.g., with the three arguments being * 4 2 100 respectively, the user would like to modify the second record on the * 4th day, and change the amount to 100. If the number of records on day is * smaller than seq_num , you should show user the warning message “WARNING: * Unable to modify a record, for not enough records on the day specified.”. * * @param day * The day of the record to be modified. * @param seq_num * The sequence number of the record within the day of it. * @param amount * The amount of the record after modified. */ public public void void modifyRecord(int int day, int int seq_num, double double amount) {} /** * Show user the overall balance by printing some leading textual prompt * followed by the balance to the console, e.g., “Balance: -90.95”. The balance * should be initialized as 0 at first, and accumulates as the user
To print out the dollar amounts in a nice format with two-decimal precision, you can make use of the printf() method within the PrintStream class as follows:
The first argument of this method is called the format string, which is a string that contains placeholders specifying properties like the width and precision of one or more output values. The following parameters include those values. More information about this method can be found here in the JavaAPI.
For methods demanding a day argument, that argument need to be validated. A valid day number is greater than or equal to 1, and less than or equal to 31. If invalid, you should show user the warning message “WARNING: Invalid day number.” Similarly, for methods requiring a senum argument, the argument need to be validated. A valid sequence number is positive. If invalid, your program should show user the warning message “WARNING: Invalid sequence number.”. For a method demanding both arguments, you should check day first and senum after, and only show warning message for the first found invalid argument.
Sample Output for display(). Sample Output for showDaySummary(2).
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
* insert/prepend/append/remove/modify records. */ public public void void showBalance() {} /** * Display all the records so far as well as the overall balance. If there * haven’t been no records in the book yet, you should display “No records in * the book yet.” before displaying the account balance. */ public public void void display() {} /** * Show the records and accumulated balance on the day specified. If in the * account book there haven’t been any records on the day specified yet, you * should display “No records on the day yet.” before displaying the accumulated * balance. * * @param day * The day of the summary to be shown. */ public public void void showDaySummary(int int day) {}
1 System.out.printf(“Balance: $%.2f\n”, yourBalance);
Sample Output for display() with zero records.
Sample Output for showDaySummary(2) with zero records with day == 2.
4. The main method of your ccountook class should continuously prompt the user to enter command and process them until the user enters a ‘q’ command to quit the program. For each of the command, you basically just need to call the corresponding method. The commands are as follows:
Command Format Corresponding Method
Command Description
i day amount insertRecord(day, amount)
‘I’nsert a record into the account book.
p amount prependRecord (amount)
‘P’repend a record into the account book.
a amount appendRecord (amount) ‘A’ppend a record into the account book.
r day seq_num removeRecord (day, seq_num)
‘R’emove a record from the account book.
m day seq_num amount
modifyRecord(day, seq_num, amount)
‘M’odify a record in the account book.
b showBalance() Show the overall ‘b’alance.
d display() ‘D’isplay all the records so far as well as the overall balance.
s day showDaySummary (day) ‘S’how the records and accumulated balance on the day specified
q – Quit the program.
Some clarifications about the commands:
Your program should support commands both in lowercase and uppercase. You may assume that for each command option entered, the number and format of arguments followed are always valid. E.g., an ‘i’ command option won’t be followed by less/more than two arguments, and the two arguments can always be interpreted as integer and double, respectively. When the user enters a command option not listed above, you should show user the warning message “WARNING: Unrecognized command.”, and then re-prompt the user to enter another command. Whenever you show the user a warning message, you should not perform the corresponding operation on the account book, nor should you exit the program. Instead, you should reprompt the user, and continue the program until the user enters a ‘q’ command. You have no need to worry about the underflow or overflow of the account balance. 5. This .txt file provides a log of a sample interactive session between a user and this program. This includes a series of prompts for the user, the commands entered by the user, and the resulting output of the program. You can prompt the user and display the output as in the text log, or in another similarly informative way. 6. Congratulations on finishing this CS300 assignment! After verifying that your work is correct, and written clearly in a style that is consistent with the course style guide, you should submit your work through zybooks. The most recent of your highest scoring submissions prior to the deadline of 17:00 on Thursday, October 26th will be used as part of your score for this assignment.
Additional grading tests will then be run against your highest scoring submission, to determine the rest of your assignment grade.