Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Just write the discountApp.java according to the given specifications. here is the GroceryBill.java public class GroceryBill { // FIELDS private Employee clerk; protected List receipt;

Just write the discountApp.java according to the given specifications. image text in transcribed

here is the GroceryBill.java

public class GroceryBill { // FIELDS private Employee clerk; protected List receipt; private double total; private double internalDiscount; // CONSTRUCTORS public GroceryBill(Employee name) { clerk = name; receipt = new ArrayList(); total = 0.0; internalDiscount = 0.0; }

public GroceryBill() { this(null); }

// MUTATORS (modifiers) public void add(Item i) { receipt.add(i); total += i.getPrice(); internalDiscount += i.getDiscount(); } // ACCESSORS (getters) public double getTotal() { return Math.rint(total * 100) / 100.0; } public Employee getClerk() { return clerk; } // private methods are called "helper" methods private String valueToString(double value) { value = Math.rint(value * 100) / 100.0; String result = "" + Math.abs(value); if(result.indexOf(".") == result.length() - 2) { result += "0"; } result = "$" + result; return result; } // complicated toString methods for Practice-IT output public String receiptToString() { String build = "items: "; for(int i = 0; i

}

Item.java

public class Item { private String name; private double price; private double discount; public Item(String name, double price, double discount) { this.name = name; this.price = price; this.discount = discount; } public double getPrice() { return price; } public double getDiscount() { return discount; } private String valueToString(double value) { String result = "" + Math.abs(value); if(result.indexOf(".") == result.length() - 2) { result += "0"; } result = "$" + result; return result; } public String toString() { return name + " " + valueToString(price) + " (-" + valueToString(discount) + ")"; } }

Employee.java

public class Employee { // Constructors and field added by Iverson // UW places fields at bottom, then changes for testing private String person; public Employee(String name) { person = name; } public Employee() { this("no name provided"); } public String toString() { return person; } // remaining code below from U.W. public int getHours() { return baseHours; // 40 hours/week }

public double getSalary() { return baseSalary; // $40,000.00 }

public int getVacationDays() { return baseVacationDays; // 10 days }

public String getVacationForm() { return baseVacationForm; // yellow }

private static int baseHours = 40; private double baseSalary = 40000.0; private int baseVacationDays = 10; private String baseVacationForm = "yellow"; public final void setBaseHours(int hours) { baseHours = hours; } public final void setBaseSalary(double salary) { baseSalary = salary; } public final void setBaseVacationDays(int days) { baseVacationDays = days; } public final void setBaseVacationForm(String form) { baseVacationForm = form; } }

SimpleConsoleTest.java

public class SimpleConsoleTest {

public static void main(String[] args) throws FileNotFoundException { Item one = new Item("Item #123020",13,2); // Item #123020 Item two = new Item("book",13,0); // a book at 13 System.out.println(one); // Item #123020 $13.00 (-$2.00) DiscountApp basket = new DiscountApp(); DiscountApp test = new DiscountApp(new Employee("you")); System.out.println(basket.getTotal()); // 0 System.out.println(basket.add(one,1)); // true System.out.println(basket); // Item #123020 $13.00 (-$2.00) System.out.println(basket.getTotal()); // 13 System.out.println(basket.add(one,8)); // true System.out.println(basket.getTotal()); // 104 System.out.println(basket.add(one,4)); // true System.out.println(basket.getTotal()); // 52 basket.add(two,9); System.out.println(basket.getTotal()); // 169 basket.setDiscount(true); System.out.println(basket.getTotal()); // 161 basket.setDiscount(false); System.out.println(basket.getTotal()); // 169 System.out.println(basket); // shows all, so output very long } }

Subtotal: 56.1950.ee) Shopping App: (adapted from textbook programming Project #1, with significant changes) Submit DiscountApp.java which must extend Grocery Bill from Chapter 9 This programming project in our textbook has scant details, so I've wrote my own. It was based on the Discount Bill an GroceryBill from Chapter 9a, but a serious design flaw was uncovered: The "total" and "discount" in those textbook classes are always increase (+=) so we can never remove anything from the list. When you make a functioning shoppi app, we need to be able to add AND remove items, so a design change is required. Bottom line, OK to extend GroceryBill, but total and discount must be recomputed in our subclass. In summary: Textbook ItemOrder will not be needed, because we can simply use Item from Chapter 9. and just add (or remove) Item objects in ArrayList . With the simple change to "protected List" in the GroceryBilljava we can manipulate the ArrayList as needed. Search the ArrayList, managing size, super.add and remove become the major conceptual tasks in getting this proje to work Above specifications will impose good object-oriented programming (OOP) by using class methods to manipulate the object. DiscountApp.java minimum specifications: one data field (NO more, others inherited) boolean for discount two constructors zero parameter and single parameter int number of item's now purchased, return true upon add(Item, int) method success returns double, checks for discounts, cannot use super getTotal() method total setDiscount(boolean) method simple one line of code, allows GUI App to work toString() standard calls toString() for all items in cart In your solution, most coding is for add and getTotal, as they need to rework the List every time. Why the name "event driven Shopping"? Because we all must know that "event driven" programs are, as we use them constantly in daily life. Whenever an "event" happens, like a click or edit or data change, then some code is run and things happen, main() is not that important. I implement from Oracle, the ActionListener and extend JFrame so each "event" like a click or tab or enter key runs a method that calls your methods that totals our shopping cart in the app. preferred: false itens: candy bar $1.35 (-$0.25) toy car $3.25 (-$8.50) apple se.se (-se.es) orange se.30 $0.05) newspaper $0.99 (-50.ee) get Total): 6.19 preferred: true looks like this: itens: candy bar $1.35 (-59.25) toy car 53.25 (-$0.50) apple se.38 (-50.es) orange 50.38 (-50.es) newspaper discount: $0.85 total: $5.34 getTotal(): 5.34 result: @pass - 0 D Above has picture has on the left ShoppingApp.java. overlaying the Practice-IT output from the Discount Bill exercise. GETTING STARTED: Some people like to start with just console code, so here are some simple tests that might be helpful by just getting the main() method to run in: SimpleConsoleTest.java This also requires from Chapter 9: Item.java Employee.java GroceryBill.java You can also create nearly empty classes and methods that are required to pass the compiler, doing trivial operations like "return 42:" when you see the real solution might be difficult. Eventually get the JFrame in ShoppingApp.java to show, then start adding code to complete the project..... Add classes to a Shopping App GUI, and make this GUI work: If you change the provided ShoppingARR driver, as we often do during development and debugging, be certain that the original ShoppingApp.java still works. else your code will not meet my specifications, and won't work when I test your solutions. Do no leave System.out calls in your final products (use as debug tool OK), and be sure your name is in all files submitted. No place in your DiscountApp.java should there be the "new" keyword, and no new object is needed for any of this assignment. You should simply call super() in your DiscountApp constructors and use super. in methods. No place in any of these Classes should you have "System.out" at all. You can use System.out for debugging and tests, but then remove it, as I should see a clean console free run of my JFrame GUI using your Classes, a real Java application

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Persuading Your Audience Strategies for

Answered: 1 week ago