Note: no late programs will be accepted for this assignment.
For this assignment, you will define two related Java programs that process a file of invoice data. An invoice file will consist of invoice records, one invoice per line, which specify the sales date, the customer ID, the number of units sold, the price per unit, and the salesperson ID. Individual entries on a line are separated by whitespace. For example,
01-01-2015 Smith1024 100 8.99 TWalker 01-06-2015 Zander99 1500 5.99 SMiller 01-01-2015 Smith1024 200 8.99 JVaska 12-20-2014 Bell222 1 12.99 TWalker
You may assume that no two invoices will have the same date, customer ID, and salesperson ID. That is, if a customer makes multiple purchases on the same day from the same salesperson, then those purchases are combined into a single invoice for that day. The customer may have separate invoices on the same day if they are purchased through different salespersons.
Write a program named TotalSales
that reads in invoices from a file (whose name is entered by the user) and displays the invoices, ordered by date, followed by the total number of units sold and the total sales amount. Invoices from the same day may be listed in any order. For example, your program interaction might appear as below (with user input in bold):
Enter the invoice file name: invoices.txt 12-20-2014 Bell222 1 12.99 TWalker 01-01-2015 Zander99 1500 5.99 SMiller 01-01-2015 Smith1024 200 8.99 JVaska 01-10-2015 Smith1024 100 8.99 TWalker Total units = 1801 Total sales = $11694.99
In completing this task, you may choose to make use of the provided Invoice class, which stores and accesses the entries in an invoice. You may choose to modify this file as desired, e.g., extending it to implement the Comparable
interface.
Write a program named IndividualSales
that reads in invoices from a file and displays the invoices and totals for individual salespersons. The user should be able to repeatedly enter a salesperson's name and see the ordered invoices, total units, and totals sales for that salesperson. Salesperson names should be treated as case-insensitive when looking up invoices. For example,
Enter the invoice file name: invoices.txt Enter a salesperson (or QUIT): TWalker 12-20-2014 Bell222 1 12.99 TWalker 01-10-2015 Smith1024 100 8.99 TWalker Total units = 101 Total sales = $911.99 Enter a salesperson (or QUIT): jvaska 01-01-2015 Smith1024 200 8.99 JVaska Total units = 200 Total sales = $1798.0 Enter a salesperson (or QUIT): QUIT Goodbye
Requirement: once the contents of the invoice file have been read, the amount of work required to look up and display a salesperson's invoices should be proportional to the number of invoices for that salesperson (NOT the total number of invoices in the file).
While you should always strive to apply object-oriented design principles (e.g., high cohesion, loose coupling) to your programs, overall design structure is not the focus of this assignment. Instead, these programs are intended to reengage you with Java constructs from CSC222 and CSC321 and so a straightforward approach is acceptable. You may want to implement supporting classes to make the tasks easier, and are free to work from code examples from past classes. You may not, however, search the Internet for code to adapt (other than small-scale examples of specific tasks, such as how to open an input file).
While overall design will not be considered in the grade for this assignment, basic elements of programming style will be part of the assessment. For example, you should choose meaningful variable names, indent consistently, and provide javadoc comments for each class and method. Your programs should also behave reasonably when given bad inputs. For example, if the user enters an input file name that does not exist, the program should not crash but should instead display a warning message.
To help assess student comfort levels and encourage coming in for help, each student will be expected to attend a 15-minute consultation with the instructor on Monday, Jan 19 and again on Monday, Jan 26.