InventoryManager.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Write a description of class InventoryManager here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import java.util.ArrayList;
  8. import java.util.Scanner;
  9. public class InventoryManager
  10. {
  11. ArrayList<Product> productList = new ArrayList<Product>();
  12. /**
  13. * Constructor for objects of class InventoryManager
  14. */
  15. public InventoryManager(){
  16. }
  17. public void addProduct (String productId, int price, int onHand){
  18. Product productName = new Product(price,productId, onHand);
  19. productList.add(productName);
  20. }
  21. public void addInventory (String productId, int quantity){
  22. if(productList.contains(productId)){
  23. int index = productList.indexOf(productId);
  24. productList.get(index).addOnHand(quantity);
  25. }else System.out.println("Product Not Found!");
  26. }
  27. public void removeProduct(String productId){
  28. int index = productList.indexOf(productId);
  29. productList.remove(index);
  30. }
  31. public void displayInventory(){
  32. for(Product p: productList){
  33. System.out.println(p.getId() + ":");
  34. System.out.println("On Hand: " + p.getOnHand());
  35. System.out.println("Price: " + p.getPrice());
  36. System.out.println("Total Inventory Value: " + p.totalValue());
  37. }
  38. }
  39. public String getStringInput(String prompt) {
  40. Scanner scanner = new Scanner(System.in);
  41. System.out.println(prompt);
  42. String userInput = scanner.nextLine();
  43. String userInput2 = userInput.toLowerCase();
  44. return userInput2;
  45. }
  46. public Integer getIntegerInput(String prompt) {
  47. Scanner scannerB = new Scanner(System.in);
  48. int b = 0;
  49. System.out.println(prompt);
  50. while(b == 0){
  51. if(scannerB.hasNextInt()){
  52. b = scannerB.nextInt();
  53. }else{
  54. System.out.print("Invalid input please start over\n");
  55. }
  56. }
  57. return b;
  58. }
  59. }