Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Simulates a grocery receipt generated by a clerk
- *
- * @author Name Van period 3
- *
- */
- public class GroceryReceipt {
- private Employee clerk;// Employee object representing the clerk generating
- // the receipt
- private String receipt;// List of items
- private double total;// Total price
- /**
- * Initializes the clerk to the passed in employee, the receipt to an empty
- * string and total to 0
- *
- * @param clerk
- * - employee generating this receipt
- */
- public GroceryReceipt(Employee clerk) {
- // Your code goes here
- this.clerk = clerk;
- receipt = "";
- total = 0;
- }
- /**
- * Returns the total amount on this receipt in dollars and cents
- *
- * @return total amount
- */
- public double getTotal() {
- // Your code goes here
- return total;
- }
- /**
- * Returns the clerk generating the information
- *
- * @return clerk
- */
- public Employee getClerk() {
- // Your code goes here
- return clerk;
- }
- /**
- * Returns the list of items
- *
- * @return receipt
- */
- public String getReceipt() {
- // Your code goes here
- return receipt;
- }
- /**
- * Adds the given item to the receipt Updates the total by adding in the the
- * items price
- *
- * @param i
- * - grocery item to be added
- */
- public void add(Item i) {
- // Your code goes here
- receipt = receipt + i.toString();
- total = i.getPrice() + total;
- }
- /**
- * Returns the value passed as a string in the dollar and cents format
- * ####.##
- *
- * @param value
- * - value to be converted to dollar and cents format
- * @return String in dollar and cents format
- */
- public String valueToString(double value) {
- // Your code goes here
- int convert = (int)(value * 100);
- if(convert == 0.0){return "0.00";}else{
- double convert2 = ((double)convert)/100;
- return "" + convert2;}
- }
- /**
- * Returns a string with list of items (one per line) and total receipt
- * amount
- *
- * @return a string with list of items and total receipt amount
- */
- public String toString() {
- // Your code goes here
- return receipt + "\nTotal: $" + valueToString(total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement