import java.util.*;
/**
 * class Items keeps track of the number and name of an item in Inventory
 * 
 * @author Kathryn
 * @version February 2007
 */
public class Items
{
    // Add static instance variable to track total inventory accross all items
    // instance variables, name and an amount
    static private int totalAmounts = 0;
    private int amount;
    private String name;

    /**
     * Constructor for objects of class Items
     */
    public Items()
    {
        // initialise instance variables
        amount = 0;
        name = null;
    }
    public Items(String n, int a) {
        if (a >= 0) {
            totalAmounts+=a;
            amount = a;
        } else {
            amount = 0;
        }
        name = n;
    }

    public Items(String n) {
        amount = 0;
        name = n;
    }
    
    public String getName() {
        return this.name;
    }
    public void setName(String newName) {
        name = newName;
    }
    public int getAmount() {
        return this.amount;
    }
    public void setAmount(int newAmount) {
        if (newAmount < 0) {
            // Error handling
        } else {
            totalAmounts += newAmount - amount;
            amount = newAmount;
        }
    }
    
    // returns a string  describing an Item object
    public String toString() {
        String objectState = amount + " of " + getName() + ". " + totalAmounts + ": Total over all Items";
        return objectState;
    }
    
    // Reads in the name of an item
    public static String getName(Scanner stdin, String type) {
//        System.out.print("Enter name for " + type + " items: ");
        return stdin.nextLine();
    }
    
    // Reads in the amount of "name" item and makes sure it is a positive amount
    public static int getPositiveInteger(Scanner stdin, String name) {
   //     System.out.print("Enter Amount of Item " + name + ": ");
        int amount = -1;
        while (amount < 0) {
            if (!stdin.hasNextInt()) {
                stdin.nextLine();
            } else {
                amount = stdin.nextInt();
                stdin.nextLine();
                if (amount >= 0) {
                    return amount;   // replace with "break;" exactly same semantics in this case
                                     // "continue;" works as well because the test is redundant with this case
                }
            }
            System.out.print("Please input a non-negative integer.");
        }
        return amount;
    }

}
