Java Case 5 Inventory Management System (χρησιμοποιώντας τη μέθοδο συλλογής για την υλοποίηση αυτής της λειτουργικότητας)

Java Case 5 Inventory Management System

/* There are 3 operations (view, modify, exit) that the administrator can perform. We can do it by means of a switch menu. -------------Inventory Management------------ 1. View inventory list 2. Modify the quantity of goods in stock 3. Exit Please enter the number of the operation to be performed: For each functional operation, we encapsulate the method so that the program is more readable. Select 1. View Inventory List function, the console prints the inventory list Select 2. Modify the item stock quantity function to update the inventory quantity of each item Select 3. Exit the function, exit the inventory management, the program ends Use collections to access product information */ import java.util.ArrayList import java.util.Scanner public class Shop{ public static void main(String[] args){ / / Define the collection, store the type variable of Laptop ArrayList array = new ArrayList() add(array) while(true){ int choose = chooseFunction() switch(choose){ / / View inventory list case 1: printArrayList(array) break case 2: changeCount(array) break case 3: return default: System.out.println('Sorry, this feature is not available for the time being') break } } } /* Modify the quantity of goods in stock */ public static void changeCount(ArrayList array){ for(int i = 0i

Σημειώστε ότι η προσθήκη μιας κλάσης που αναφέρεται από την εισαγωγή αποφεύγει τη συλλογή σφαλμάτων που δεν μπορούν να βρεθούν.

Ορίστε μια τάξη που ονομάζεται Laptop

/* Create a class: computer Included attributes: Brand Size Price Stock */ public class Laptop{ String brand//brand Double size//size Double price//price Int count//inventory count }

Το αποτέλεσμα είναι: