Question: on netbeans Week 5 Practice Program - Pizza File/IO Class in this week's practice program, we are stepping up our game a bit and we

on netbeans

Week 5 Practice Program - Pizza File/IO

Class in this week's practice program, we are "stepping up our game" a bit and we are going to begin seeing a more complex, but more "real world" object oriented program structure. The good news is that for the Pizza Practice program you are not going to start from scratch, and everything you are being asked to do in this program is demonstrated in the example Circle program. Also, keep in mind that the Week 5, 6, and Course project assignments will be requiring you to do perform these programming techniques. So, let's practice some of the techniques.

Start by downloading the attached "Week5_Pizza_FileIO_Shell.zip" program, unzip the program and open it up into Netbean. Then before you start, make sure add the Helpers project to the file (this program would take a week to build without the helpers). The shell project will compile and execute, and even read a stream file and populate the list with data from a string file.

Click to download the Pizza Program File IO Shell Project

You are then asked to complete the following features:

Add a PizzaList class that:

An private array list that will hold the stock objects.

Public methods that:

Add an object to the list

Remove an object from the list

Interacts with the given FileIO_Streams object to save the list as strings.

Interacts with the given FileIO_Streams object to retrieve the list as strings

Interacts with the FileIO_Objects object to to save the list as objects

Interacts with the FileIO_Objects object to retreive the list as objects

A method to calculate the total value of all the orders.

FileIO_Streams Class

You can use the provided FileIO_Streams class as is, and you will want to integrate the operations into the PizzaList class.

FileIO_Object Class

Use the provided FileIO_Object class, which is not fully implemented, and add the following public methods:

writeData that accepts an ArrayList of PizzaOrders and writes the objects to the given file and returns the number of records written to the file

readData that returns an ArrayList of PizzaOrders that are read from the given file.

Graphical User Interface

Update the given graphical user interface to:

Save the list in the Order list to a file using both types of file I/O (streams and objects).

Retrieve the list from either the string stream or the object stream and populate the list.

Add a menu item tothe Order Summary menu to update the total (just replicate Update Total Button)

unzip files

package business; import java.util.ArrayList; import javax.swing.DefaultListModel; import data.*; import helpers.*;

public class OrderList { private ArrayList orderList; public OrderList() { orderList = new ArrayList<>(); } public void addOrder(PizzaOrder aOrder) { if (aOrder != null) { orderList.add(aOrder); } } public void removeOrder(PizzaOrder aOrder) { if (aOrder != null) { orderList.remove(aOrder); } } public int saveOrderList(Boolean asObjects) { int count; if(asObjects) { //TODO: add call to add to file as objects count = 0; } else { FileIO_Streams streamFile = new FileIO_Streams(); count = streamFile.writeData(orderList); } return count; } public int retrieveOrderList(DefaultListModel listModel, Boolean asObjects) { int count = 0; if(asObjects) { //TODO: add call to get list using object streams count = 0; orderList.clear(); } else { FileIO_Streams streamFile = new FileIO_Streams(); orderList = streamFile.readData(); } if (!orderList.isEmpty()) { listModel.clear(); count = orderList.size(); for(PizzaOrder order : orderList) { listModel.addElement(order); } } return count; } public String getOrderSummary() { double totalOrder = 0; double averagePrice = 0; int count = 0; if (!orderList.isEmpty()) { for(PizzaOrder aOrder:orderList) { totalOrder += aOrder.getTotal(); count++; } if (count > 0) { averagePrice = totalOrder/count; } } StringBuilder str = new StringBuilder(); str.append("Pizza Order Summary: "); str.append("Number of total orders: "); str.append(count); str.append(" "); str.append("Total Price of Orders: "); str.append(OutputHelpers.formattedCurrency(totalOrder)); str.append(" "); str.append("Average Price of Orders: "); str.append(OutputHelpers.formattedCurrency(averagePrice)); return str.toString(); } }

package business;

import helpers.StringHelpers;

public class Person { private static final String DEFAULT_NAME = "Not Given"; private String firstName; private String lastName; public Person() { this.firstName = DEFAULT_NAME; this.lastName = DEFAULT_NAME; } public Person(String firstName, String lastName) { setFirstName(firstName); setLastName(lastName); } public String getFirstName() { return firstName; }

public final void setFirstName(String firstName) { if (!StringHelpers.IsNullOrEmpty(firstName)) { this.firstName = firstName; } else { this.firstName = DEFAULT_NAME; } } public String getLastName() { return lastName; } public final void setLastName(String lastName) { if (!StringHelpers.IsNullOrEmpty(lastName)) { this.lastName = lastName; } else { this.lastName = DEFAULT_NAME; } } public String getFullName() { return firstName + " " + lastName; } }

package business;

import helpers.*;

public class PizzaOrder { public enum PizzaSize { Small, Medium, Large } public static final double DEFAULT_PRICE = 12.99; public static final double MIN_PRICE = 0; public static final double MAX_PRICE = 12.99; public static final String DEFAULT_TYPE = "Item"; private static final double SMALL_PRICE = 6.99; private static final double MEDIUM_PRICE = 9.99; private static final double LARGE_PRICE = 12.99; private static final double CHEESE_COST = 1.50; private static final double SAUSAGE_COST = 2.25; private static final double HAM_COST = 2.5; private final Person customer = new Person(); private boolean cheeseSelected = false; private boolean sausageSelected = false; private boolean hamSelected = false; private PizzaSize pizzaSize; private double sizeCost; private double totalCost = 0; public PizzaOrder() { clearOrder(); } public void setTotal(double total) { this.totalCost = total; } public double getTotal() { calculateTotalCost(); return totalCost; } public String getTotalCost() { calculateTotalCost(); return OutputHelpers.formattedCurrency(totalCost); } public void setPizzaSize(PizzaSize size) { pizzaSize = size; } public void setPizzaSize(String size) { if(size.compareToIgnoreCase("small") == 0) { pizzaSize = PizzaSize.Small; } else if (size.compareToIgnoreCase("medium") == 0) { pizzaSize = PizzaSize.Medium; } else if (size.compareToIgnoreCase("large") == 0) { pizzaSize = PizzaSize.Large; } else { pizzaSize = PizzaSize.Large; } } public void setPizzaSize(int size) { switch(size) { case 0: pizzaSize = PizzaSize.Small; break; case 1: pizzaSize = PizzaSize.Medium; break; case 2: pizzaSize = PizzaSize.Large; break; default: pizzaSize = PizzaSize.Large; break; } } public String getPizzaSize() { String str; switch (pizzaSize) { case Small: str = "Small"; break; case Medium: str = "Medium"; break; case Large: str = "Large"; break; default: str = "Large"; break; } return str; } private void calculateTotalCost() { totalCost = 0; switch (pizzaSize) { case Small: sizeCost = SMALL_PRICE; break; case Medium: sizeCost = MEDIUM_PRICE; break; case Large: sizeCost = LARGE_PRICE; break; default: sizeCost = LARGE_PRICE; break; } totalCost = sizeCost; if (cheeseSelected) { totalCost += CHEESE_COST; } if (sausageSelected) { totalCost += SAUSAGE_COST; } if (hamSelected) { totalCost += HAM_COST; } } public void setFirstName(String firstName){ customer.setFirstName(firstName); } public String getFirstName() { return customer.getFirstName(); } public void setLastName(String lastName) { customer.setLastName(lastName); } public String getLastName() { return customer.getLastName(); } public String getFullName() { return customer.getFullName(); } public void setCheese(boolean selected) { cheeseSelected = selected; } public Boolean getCheese() { return cheeseSelected; } public void setSausage(boolean selected) { sausageSelected = selected; } public Boolean getSausage() { return sausageSelected; } public void setHam(boolean selected) { hamSelected = selected; } public Boolean getHam() { return hamSelected; } public void clearOrder() { setPizzaSize(PizzaSize.Large); setCheese(false); setHam(false); setSausage(false); }

public String getOrderSummary() { StringBuilder str = new StringBuilder(); str.append("Pizza order for: "); str.append(customer.getFullName()); if (cheeseSelected) { str.append(" Extra cheese: "); str.append(OutputHelpers.formattedCurrency(CHEESE_COST)); } if (sausageSelected) { str.append(" Sausage: "); str.append(OutputHelpers.formattedCurrency(SAUSAGE_COST)); } if (hamSelected) { str.append(" Ham: "); str.append(OutputHelpers.formattedCurrency(HAM_COST)); } str.append (" Size: "); str.append(getPizzaSize()); str.append(": "); str.append(OutputHelpers.formattedCurrency(sizeCost)); str.append(" Total: "); str.append(getTotalCost()); return str.toString(); } public String toString() { return customer.getFullName(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!