我只是在寻找一些余地,以了解如何让下面的空方法响应我的硬编码 arrayList(如果需要,还有 HashMap。)。如果没有人可以直接帮助我,我会理解的,只是一些好的建议。
import java.io.IOException;
import java.text.ParseException;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Collections;
import java.util.Set;
@SuppressWarnings("unused")
public class Inventory
{
Scanner in = new Scanner(System.in);
ArrayList<Sellable> groceries;
HashMap<String, Integer> stock;
public Inventory()
{
groceries = new ArrayList<Sellable>();
stock = new HashMap <String,Integer> ();
//HARDCODING...:
Sellable n1 = new Produce("Corn", 3, 3.00);
Sellable n2 = new Snack("Natural Popcorn Seeds", 2.50);
Sellable n3 = new Produce("Potatoes", 3, 3.00);
Sellable n4 = new Snack("Organic Potato Chips", 2.50);
Sellable n5 = new Produce("Apples", 5, 1.75);
Sellable n6 = new Snack("Apple Juice - 128 oz.", 3.50);
Sellable n7 = new Produce("Oranges", 5, 1.75);
Sellable n8 = new Snack("Orange Juice - 128 oz.", 3.50);
//ADD TO HASHMAP
groceries.add(n1);
groceries.add(n2);
groceries.add(n3);
groceries.add(n4);
groceries.add(n5);
groceries.add(n6);
groceries.add(n7);
groceries.add(n8);
//PUT UP FOR PRINTING
stock.put(n1.getName(), 50);
stock.put(n2.getName(), 100);
stock.put(n3.getName(), 50);
stock.put(n4.getName(), 100);
stock.put(n5.getName(), 50);
stock.put(n6.getName(), 100);
stock.put(n7.getName(), 50);
stock.put(n8.getName(), 100);
}
public void add(Sellable SE)
{
}
public boolean decrementStock(String name)
{
}
public boolean decrementStock(Sellable SE)
{
}
public boolean incrementStock(String SE)
{
}