StupidShoppingList


/*
 * ShoppingItem.java
 * Author: John O'Connor
 * Date: 10/26/2017
 * License: MIT
 */

package stupidshoppinglist;

/**
 *
 * @author ncc
 */
public class ShoppingItem {
    private double quantity;
    private String title;
    private String description;
    private double unitPrice;

    public double calculateTotal() {
        return quantity * unitPrice;
    }
    /**
     * @return the quantity
     */
    public double getQuantity() {
        return quantity;
    }

    /**
     * @param quantity the quantity to set
     */
    public void setQuantity(double quantity) {
        this.quantity = quantity;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the unitPrice
     */
    public double getUnitPrice() {
        return unitPrice;
    }

    /**
     * @param unitPrice the unitPrice to set
     */
    public void setUnitPrice(double unitPrice) {
        this.unitPrice = unitPrice;
    }
    
    @Override
    public String toString() {
        return this.title + "\n\t\t" + this.description + "\n\t\tquantity: " + this.quantity + "\n\t\tPrice" + this.unitPrice + "\n";
        
    }
    
    
    public boolean equals(ShoppingItem itemToCompare) {
        if (this.description.equals(itemToCompare.description)) {
            return true;
        }
        return false;
    }
    
}

/*
 * ShoppingList.java
 * Author: John O'Connor
 * Date: 10/26/2017
 * License: MIT
 */

package stupidshoppinglist;

import java.util.ArrayList;

/**
 *
 * @author ncc
 */
public class ShoppingList {
    private String name;
    private ArrayList<ShoppingItem> items;
    
    public ShoppingList() {
        items = new ArrayList();
    }
    
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public Double calculateTotal() {
        Double sum = 0.0;
        for (ShoppingItem i : items) {
            sum += i.calculateTotal();
        }
        return sum;
    }
    
    public void addItem(ShoppingItem item) {
        items.add(item);
    }
    
    public void removeItem(ShoppingItem item) {
        items.remove(item);
    }
    
    public ArrayList<ShoppingItem> getItems() {
        return items;
    }
    
    public boolean isItemInList(ShoppingItem thisItem) {
        for (ShoppingItem i: this.items) {
            if (thisItem.equals(i)) {
                return true;
            }
        }
        return false;
    }
    
    @Override
    public String toString() {
        String returnString = "List Name: " + this.name;
        returnString += "\titems: \n";
        for (ShoppingItem item: this.items) {
            returnString += "\t" + item.toString();
            returnString += "\n";
        }
        return returnString;
    }
}

/*
 * StupidShoppingList.java
 * Author: John O'Connor
 * Date: 10/26/2017
 * License: MIT
 */

package stupidshoppinglist;

import java.util.Scanner;

/**
 *
 * @author ncc
 */
public class StupidShoppingList {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter a shopping list name (q to quit):");
        String name = input.nextLine();
        String quitCharacter = "q";
        Double a = 5.0;
        Double b = 10.0;
        a.equals(b);
        if (name.equals(quitCharacter)) {
            return;
        }
        ShoppingList list = new ShoppingList();
        list.setName(name);
        Boolean done = false;
        System.out.println(list);
        while (!done) {
            System.out.println("Press 1 to create a new item, or 0 to display list and quit:");
            int menu = input.nextInt();
            if (menu == 0) {
                done = true;
            } else {
                ShoppingItem item = new ShoppingItem();
                System.out.println("Enter a name for your item: ");
                item.setTitle(input.nextLine());
                System.out.println("Enter a description for your item: ");
                item.setDescription(input.nextLine());
                System.out.println("Enter a price for your item: ");
                item.setUnitPrice(input.nextDouble());
                System.out.println("Enter a quantity of items:");
                item.setQuantity(input.nextDouble());
                list.addItem(item);
                System.out.println(list);
            }
        }
        System.gc();
        ShoppingItem s = new ShoppingItem();
        System.out.println(list);
    }
    
}