/** * CS149 - Introduction to Programming * Department of Computer Science * James Madison University * @version Fall 2018 */
See submission details below for all due dates and submission details. Note there are multiple submission parts.
This assignment should be completed individually to maximize learning. It is important that you adhere to the Course Policies, particularly the section on Programming Assignments. Also relevant is the JMU Honor Code.
Your Bakery.java program has been a tremendous success, and the bakery is selling more goods than ever before! To keep up with demand, the owner has opened up a warehouse to handle all orders with quantities 100 or over and needs you to implement more features for the program to be used at the warehouse:
Your program must read in and calculate the total for three products.
Products are counted in terms of dozens, with a leftover amount.
A standard discount of 20% is given to each dozen products, but not to additional products.
Because discounts are for dozens, customer's have requested an average product cost.
All decimal values must be formatted with two digits of precision.
Since the program is starting to get long, you will need to improve
your PA1 submission by organizing it into multiple well-documented methods. Make a
copy of your PA1 source file and name it Bakery2.java
.
Don't forget to rename the class to Bakery2
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 javadoc comments with @param
and @return
tags where applicable.
The constants for the tax rate and discount rate will be shared across the whole class. To declare these where the whole class can make use of them, copy the following lines directly beneath the class header (i.e., the first element inside the class):
public static final double TAX_RATE = 5.3;
public static final int DISCOUNT = 20;
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.
The final
keyword means that the variable is only assigned once and is a constant.
(We'll learn more about these concepts later in the semester.)
Each of the methods below should be declared above main and implemented exactly as described. Only one Scanner should be declared and used in the entire class. It should be declared in main and then passed as an argument to each method as appropriate.
public static double inputNumber(Scanner in, String prompt)
This method will prompt the user using the prompt passed to it, read in the user's response
as a double from the Scanner in, consume the rest of the line (i.e., the \n
character),
and then return the response
as a double.
Example: inputNumber(in, "Enter Customer's Product 1 Price: ") where the user enters 2 would return 2.0
public static String inputLine(Scanner in, String prompt)
This method will prompt the user using the prompt passed to it, read in the user's response as a String from the Scanner in and then return the response as a String.
Example: inputLine(in, "Enter Customer's Personal Name: ") where the user enters Ali would return "Ali"
public static void printHeading(String firstName, String lastName)
This method will must print a blank line, the logo for the bakery (2 lines), the first and last name of the customer on one line with a single space in between, and the date this assignment is due, followed by another blank line. This should look similar to the heading in PA1, but have the due date of this assignment.
public static double printProduct(String code, int quantity, double price)
This method will print the individual product information for one line in the table and calculate the average price for each product after the discount is applied, so you will call it three times. The columns will each be separated with a single tab character and the price will be preceded by a $. Each column should be calculated and formatted as follows:
The product is the code entered by the user and should be printed out as a right justified String with a minimum of 7 spaces.
This is the number of DISCOUNT_NUM products in the quantity entered by the user for this product. It should be printed as a right justified integer with a minimum of 5 spaces.
This is the remainder of the number of this product leftover after dividing the quantity entered by the user by the DISCOUNT_NUM. It should be also be printed as a right justified integer with a minimum of 5 spaces.
The price per one product is the average price of the product after the discount has been applied to the quantity that is an even multiple of DISCOUNT_NUM. (Think mod) It should be formatted as an unjustified floating point number with with only two decimal places and an unspecified number of total spaces.
Example: printProduct("cake22", 100, 1.00) would printout cake22 8 4 $0.81 spaced as described above and would return the value 0.808. See the expected output examples shown below for precise details.
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 declare a single Scanner that will be passed to each method. 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).
The files below contain example input and corresponding expected output of a finished program. You must use these files to perform diff/meld testing similar to the Command Line Testing Lab lab. It is highly unlikely that you will be able to get the format exactly right without using this testing technique. This is the purpose of the detailed description and formatting requirements - to get you to use command-line testing.
This assignment has two parts that should be completed in order. By the first deadline you must complete a readiness quiz in Canvas, by the second deadline you must submit your completed code through AutoLab.
Read this entire document and complete the quiz in Canvas. The grading for this quiz is all-or-nothing. You must answer all questions correctly by the deadline to get any credit. You will have as many attempts as you need, but if you do not answer all questions correctly by the deadline or you will receive no credit for this part.
Upload your
completed Bakery2.java
file through AutoLab.
You must implement the above in java, creating a file called Bakery2.java
. Before uploading your Bakery.java
file,
be sure to complete the following steps carefully:
Your submission will be graded using the following criteria:
Requirement | Points |
---|---|
PART A: Readiness Quiz | 10 |
PART B: Checkstyle | 10 |
PART B: Javadoc and Comments | 10 |
PART B: Accurate algebraic calculations | 20 |
PART B: Accurate modulus calculations | 10 |
PART B: I/O and Formatting | 10 |
PART B: Proper method calls | 10 |
PART B: Passes Diff Testing | 10 |
PART B: Instructor grading based on style and code quality | 10 |
Don't put off submission until the last possible minute! Any submission system may become bogged down when it receives a large number of submissions. You may have some unanticipated difficulties uploading your code. It is your responsibility to take these possibilities into account and submit early enough to ensure that the submission process is completed before the deadline.
Format the floating point values in the final report of totals as right justified numbers in an unspecified number of spaces with 2 places after the decimal point. Also, compute the discount by subtracting the discounted price from the full price. Compute the discounted price by multiplying each average price returned by printProduct by the quantity entered by the user.
For a nice summary of printf format specifiers, look here.
Why did we
use the colors above (input/output)?
This assignment was originally developed by Nathan Sprague and repurposed by Dee Weikle.