How would i apply the append method to the Section highlighted (This Section).
Help would truly appreciated.
import java.util.*; public class StockData { private static class Item { Item(String n, double p, int q) { name = n; price = p; quantity = q; } // get methods public String getName() { return name; } public double getPrice() { return price; } public int getQuantity() { return quantity; } // instance variables private String name; private double price; private int quantity; } private static Map<String, Item> stock = new HashMap<String, Item>(); static { // if you want to have extra stock items, put them in here // use the same style - keys should be 7 digit Strings stock.put("0000000", new Item("Bath towel", 5.50, 10)); stock.put("1111111", new Item("Plebney light", 20.00, 5)); stock.put("2222222", new Item("Gorilla suit", 30.00, 7)); stock.put("3333333", new Item("Whizz games console", 50.00, 8)); stock.put("4444444", new Item("Oven", 200.00, 4)); } public static String getName(String key) { Item item = stock.get(key); if (item == null) return null; // null means no such item else return item.getName(); } public static double getPrice(String key) { Item item = stock.get(key); if (item == null) return -1.0; // negative price means no such item else return item.getPrice(); } public static int getQuantity(String key) { Item item = stock.get(key); if (item == null) return -1; // negative quantity means no such item else return item.getQuantity(); } //This section :^: // update stock levels // extra is +ve if adding stock // extra is -ve if selling stock public static void update(String key, int extra) {//was int extra Item item = stock.get(key); if (item != null) item.quantity += extra;//was int extra //This Section :^: } public static void close() { // Does nothing for this static version. // Write a statement to close the database when you are using one } }
Thank u