Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Cart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.ArrayList;
import java.util.Hashtable;

public class Cart {

private Hashtable<Product, Number> items;
private double total;

public Cart(){
items = new Hashtable<Product, Number>();
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;
}
}
Binary file added DIagram2.pdf
Binary file not shown.
66 changes: 66 additions & 0 deletions Final_Driver.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
2 changes: 2 additions & 0 deletions GroceryStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class GroceryStore {}

33 changes: 33 additions & 0 deletions Product.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
68 changes: 68 additions & 0 deletions Shopper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import java.util.ArrayList;
import java.util.InputMismatchException;

public class Shopper {

private ArrayList<String> groceryList;
private double budget;
private Cart cart;
private int location;

public Shopper(){
this.groceryList = new ArrayList<String>();
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;
}
}

}
Binary file added cheatSheet.pdf
Binary file not shown.
8 changes: 0 additions & 8 deletions cheatsheet.md

This file was deleted.

88 changes: 88 additions & 0 deletions inventory.txt
Original file line number Diff line number Diff line change
@@ -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