Question
NEED TO CREATE A FILE NOT FOUND EXCEPTION CLASS CALLED GROCERYEXCEPTION PLEASE HELP! import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class Driver {
NEED TO CREATE A FILE NOT FOUND EXCEPTION CLASS CALLED GROCERYEXCEPTION
PLEASE HELP!
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner;
public class Driver { static ArrayList> orders = new ArrayList<>();
public static void main(String[] args) { GroceryManager manager = new GroceryManager();
// stock store try { manager.readInventory(); readOrders(); } catch (FileNotFoundException e) { e.printStackTrace(); } System.out.println("------------ Initial Inventory ------------"); manager.displayInventory();
// purchase items System.out.println("------------ Processing Orders ------------"); for (GroceryOrder order: orders) try{ manager.processOrder(order);} catch(GroceryException e){ System.out.println(e); } manager.displayInventory();
// sort inventory manager.sortByName(); System.out.println("------------ Sort by name ------------"); manager.displayInventory();
manager.sortByPrice(); System.out.println("------------ Sort by price ------------"); manager.displayInventory();
System.out.println("------------ Reorder List ------------"); System.out.println(manager.getReorderList()); }
public static void readOrders() { Scanner input = null; String line; String[] parts; try { input = new Scanner(new FileInputStream("groceryOrders.txt"));
while (input.hasNext()) { GroceryOrder list = new GroceryOrder(); input.nextLine();//ORDER line = input.nextLine(); parts = line.split(" "); list.add(new Dairy(parts[1], Integer.parseInt(parts[2]))); line = input.nextLine(); parts = line.split(" "); list.add(new Produce(parts[1], Integer.parseInt(parts[2]))); line = input.nextLine(); parts = line.split(" "); list.add(new Meat(parts[1], Integer.parseInt(parts[2])));
orders.add(list);
} } catch (Exception e) { System.out.println(e); } finally { input.close(); } } }
//groceryorder
import java.util.ArrayList; public class GroceryOrder extends ArrayList { }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started