diff --git a/Cart.java b/Cart.java new file mode 100644 index 00000000..370663ab --- /dev/null +++ b/Cart.java @@ -0,0 +1,27 @@ +import java.util.ArrayList; +import java.util.Hashtable; + +public class Cart { + + private Hashtable items; + private double total; + + public Cart(){ + items = new Hashtable(); + total = 0; + } + + public void addToCart(Product item, int amount){ + while(amount>0){ + items.add(item); + amount--; + } + } + + public double getTotal(){ + for(Product item : items){ + total += item.getPrice(); + } + return total; + } +} diff --git a/DIagram2.pdf b/DIagram2.pdf new file mode 100644 index 00000000..e570cd12 Binary files /dev/null and b/DIagram2.pdf differ diff --git a/Final_Driver.java b/Final_Driver.java new file mode 100644 index 00000000..a4631628 --- /dev/null +++ b/Final_Driver.java @@ -0,0 +1,66 @@ +import java.util.Scanner; +import java.io.File; +import java.io.FileNotFoundException;; + +public class Final_Driver { + public static void main(String[] args){ + + //Flag for when game should end + boolean playing = true; + boolean valid = true; + //Scanner object for user input + Scanner keyboard = new Scanner(System.in); + //Store user response + String response = ""; + + //Intro message + System.out.println("**************************************************"); + System.out.println("WELCOME TO GRACE'S REASONABLY PRICED GROCERY STORE!"); + System.out.println("***************************************************"); + //Instatiate GroceryStore + //Instatiate Shopper + Shopper user = new Shopper(); + + do{ + //Prompt user for budget + System.out.println("First, what is your budget for groceries?"); + System.out.println("Please enter your budget in dollars and cents in decimal format without any extra characters."); + do{ + response = keyboard.nextLine(); + valid = user.setBudget(response); + }while(!valid); + + //Prompt user to enter grocery list + System.out.printf("Great, your budget is $%.2f.", user.getBudget()); + System.out.println(); + System.out.println("Enter items on your list. Enter DONE when you are finished making your list"); + //while loop taking in input and adding to list until user enters "done" + response = keyboard.nextLine(); + while(!response.toUpperCase().equals("DONE")){ + user.addToList(response); + response = keyboard.nextLine(); + } + + System.out.println("Enter the grocery store to get started."); + response = keyboard.nextLine(); + + while(!response.toUpperCase().equals("ENTER")){ + if(response.toUpperCase().equals("QUIT")){ + System.out.println("You have quit the game."); + System.exit(0); + } + else{ + System.out.println("ERROR! Please enter store to get started."); + response = keyboard.nextLine(); + } + } + user.enterStore(); + + //BRUH FIGURE OUT HOW TO CHECK COMMANDS + System.out.println("Time to get shopping!"); + System.out.println("Your available commands are: LIST, ADD, PRICE, "); + + }while(playing); + } + +} diff --git a/GroceryStore.java b/GroceryStore.java new file mode 100644 index 00000000..510b3dd3 --- /dev/null +++ b/GroceryStore.java @@ -0,0 +1,2 @@ +public class GroceryStore {} + diff --git a/Product.java b/Product.java new file mode 100644 index 00000000..2213a365 --- /dev/null +++ b/Product.java @@ -0,0 +1,33 @@ +public class Product{ + + private int aisle; + private String name; + private double price; + private boolean byEach; + + + public Product(int aisle, String name, double price, boolean byEach){ + this.aisle = aisle; + this.name = name; + this.price = price; + this.byEach = byEach; + + } + + public int getAisle(){ + return aisle; + } + + public String getName(){ + return name; + } + + public double getPrice(){ + return price; + } + + public boolean getType(){ + return byEach; + } + +} \ No newline at end of file diff --git a/Shopper.java b/Shopper.java new file mode 100644 index 00000000..840b7a38 --- /dev/null +++ b/Shopper.java @@ -0,0 +1,68 @@ +import java.util.ArrayList; +import java.util.InputMismatchException; + +public class Shopper { + + private ArrayList groceryList; + private double budget; + private Cart cart; + private int location; + + public Shopper(){ + this.groceryList = new ArrayList(); + this.budget = 0; + this.cart = new Cart(); + this.location = 0; + } + + public boolean setBudget(String budget){ + try{ + this.budget = Double.parseDouble(budget); + if(this.budget <= 0){ + throw new InputMismatchException(); + } + else{ + return true; + } + } catch (Exception a){ + System.out.println("Invalid input."); + System.out.println("Budget must be greater than $0 and input may not contain any characters besides decimals and numbers."); + return false; + } + } + + public double getBudget(){ + return this.budget; + } + + public int getLocation(){ + return this.location; + } + + + public void addToList(String item){ + groceryList.add(item.toLowerCase()); + } + + public void removeFromList(String item){ + groceryList.remove(item.toLowerCase()); + } + + public void enterStore(){ + this.location = 1; + System.out.println("You have entered the store! You are in Aisle 1: The grocery aisle."); + } + + public boolean goToAisle(int aisle){ + if(this.location == 0){ + System.out.println("You are outside the store. Please enter the store."); + return false; + } + else{ + this.location = aisle; + System.out.println("You are now in aisle " + aisle "."); + return true; + } + } + +} diff --git a/cheatSheet.pdf b/cheatSheet.pdf new file mode 100644 index 00000000..f8bf459f Binary files /dev/null and b/cheatSheet.pdf differ diff --git a/cheatsheet.md b/cheatsheet.md deleted file mode 100644 index d5dc4294..00000000 --- a/cheatsheet.md +++ /dev/null @@ -1,8 +0,0 @@ -This file will contain documentation for all commands available in your game. - -Note: It's a good idea to also make this list available inside the game, in response to a `HELP` command. - - -# SPOILER ALERT - -If your game includes challenges that must be overcome to win, also list them below. diff --git a/inventory.txt b/inventory.txt new file mode 100644 index 00000000..d5c9e6ac --- /dev/null +++ b/inventory.txt @@ -0,0 +1,88 @@ +APPLE +50 +1.29 +A +BLUEBERRIES +10 +2.50 +C +RASPBERRIES +10 +2.50 +C +STRAWBERRIES +20 +5.00 +C +BLACKBERRIES +10 +2.50 +C +GRAPES +10 +1.50 +C +PEAR +25 +0.50 +A +LEMON +40 +0.50 +A +LIME +45 +0.40 +A +BELL PEPPER +20 +1.50 +A +GREEN BEANS +15 +2.00 +C +LETTUCE +20 +2.00 +B +CELERY +10 +3.00 +B +CARROT +50 +1.00 +A +ONION +20 +0.50 +A +GARLIC +40 +0.60 +A +TOMATO +35 +2.50 +A +SPINACH +15 +6.00 +B +POTATO +60 +0.75 +A +SWEET POTATO +40 +0.95 +A +KALE +10 +1.50 +B +CANTELOUPE +10 +2.50 +A