Question: Fix my method called store_interval in the class FoodSupplier that uses file manipulation to remove all of a stores orders between the startDate and endDate
Fix my method called store_interval in the class FoodSupplier that uses file manipulation to remove all of a stores orders between the startDate and endDate from a HashMap database called orders for a specific company.
The file that has to be manipulated is called supply.dat. Currently, the code removes everything from the file supply.dat.
The supply.dat file has contents like this:
05-28-2011 FiveGuys#2 burgers-2 buns-6 fries-8 cokesyrup-3 cups-1 napkins-1 straws-8 05-28-2011 FiveGuys#2 buns-3 fries-6 straws-6 05-29-2011 Hardees#61 burgers-3 buns-1 fries-1 cokesyrup-3 cups-1 napkins-5 straws-5 05-30-2011 BurgerKing#26 burgers-1 buns-3 fries-1 cokesyrup-2 cups-1 05-30-2011 BurgerKing#11 cokesyrup-1 cups-4 napkins-1 straws-3 05-30-2011 Wendys#23 burgers-8 buns-1 fries-4 cokesyrup-1 napkins-1 05-31-2011 BurgerKing#31 buns-5 cokesyrup-6 napkins-1
FoodSupplier:
public class FoodSupplier { Map
public void addOrder(String order) { String date_str = order.split(" ")[0]; // Date order = order.substring(order.indexOf(" ") + 1, order.length()); // Everything else String[] date_split_strs = date_str.split("-"); int[] date_split_ints = new int[3]; int y = 0; for (String x : date_split_strs) { date_split_ints[y++] = Integer.parseInt(x); } Date order_date = new Date(date_split_ints[2] - 1900, date_split_ints[0] - 1, date_split_ints[1]); if (orders.get(order_date) == null) { orders.put(order_date, new LinkedList
public void store_interval(Date startDate, Date endDate, String company) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter("supply.dat"));
for (Date date : orders.keySet()) {
if (date.after(startDate) && date.before(endDate)) {
for (Order order : orders.get(date)) {
if (order.getCompanyName().equals(company)) {
bw.write(order.toString());
}
}
}
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
The Order class is given below:
import java.util.HashMap; import java.util.Map; public class Order { String company; Map
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
