/**
 * CS139 - Programming Fundamentals
 * Department of Computer Science
 * James Madison University
 * @version Spring 2016
 */

PA2: Better Invoice (Methods)

Objectives

Instructions

Your Invoice.java program has been a tremendous success, and the bakery is selling more goods than ever before! To keep up with demand, the owner needs you to implement two more features:

Since the program is starting to get long, you will need to improve your PA1 submission by organizing it into multiple methods. Make a copy of your PA1 source file and name it Invoice2.java. Don't forget to rename the class to Invoice2 for it to compile, and while you're at it update the @version tag. Then add the following methods to your program (above main). An important part of this assignment will be to write method documentation comments with @param and @return tags where applicable.

Both input methods must display the provided prompt and read a single number or line of text from the keyboard, returning the applicable data type. In addition, inputNumber must consume the rest of the line (i.e., the \n character). The printItem method must print one line of the output using the format required by PA1. Note that you will call this method three times. Finally, printTotals must perform necessary calculations and display the last six lines of output, including blank lines.

You will still have a main method as before, but it will primarily call the other methods to do most (but not all) of the work. In particular, main should NOT use the Scanner at all. As before, many variables (but not all) will be declared in main. Make sure you do not duplicate any effort between your main method and the supporting methods.

As in the previous assignment, there is no need to handle invalid user input (e.g., the user typing in a string when you're expecting a double).

One Caveat

In order to divide input across multiple methods, you will need to create a single Scanner object that is shared across the entire class. Copy/paste the following line directly beneath the class header (i.e., the first element inside the class):

public static Scanner input = new Scanner(System.in);

The public keyword means the variable is visible outside this class. The static keyword means the variable will be shared by all instances of the class. (We'll learn more about these concepts later in the semester.) Make sure you delete all other declaration and initialization statements for your Scanner from PA1. Otherwise, you may end up interfering with the static variable input.

NOTE 1: Your code will not pass the Web-CAT submission tests unless your input variable is declared and initialized exactly as described above.

NOTE 2: Checkstyle will complain about the declaration of the input variable. You should see the following warning:

Variable 'input' must be private and have accessor methods
Ignore this warning. Web-CAT has been configured to overlook it.

Examples and Testing

The two files below contain example interactions with a finished program. You are encouraged to use these files to perform diff/meld testing long the lines of the Arithmetic and Testing lab.

Submission

Before uploading your Invoice2.java file to Web-CAT, be sure to complete the following steps.

Your submission will be graded using the following criteria:

Points
Web-CAT Functionality Tests40
Web-CAT Checkstyle Tests40
Style and Code Organization20

Note that Web-CAT is not designed to be a testing tool. You should test your code before submission to ensure it satisfies the project requirements. In order to discourage the misuse of Web-CAT there will be a penalty for excessive submissions. The first 10 submissions are free. Each submission beyond 10 will result in a .5 reduction in the final score.

Honor Code

This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 139, and the instructor. Copying work from another student or the Internet is an honor code violation and will be grounds for a reduced or failing grade in the course.

Acknowledgments

This assignment was originally developed by Chris Mayfield.