array list menú
Publicado por andre (15 intervenciones) el 17/06/2021 20:56:09
tengo este código necesito que cada método agregue un producto y la cantidad , elimine, muestre y ordene productos del arraylist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
public class ShoppingList1 {
public static void main(String[] args) {
// Initialize variables
Scanner sIn = new Scanner(System.in); // Input Scanner for String
ArrayList<String> shoppingList = new ArrayList<String>(); // ArrayList for shoppingList
String choice; // Holds user input of type String
boolean done = false; // Keeps program running until user wants to quit
// Keep running the program until the user quits
do {
// Print out the menu to the console
System.out.println();
System.out.println("1. agregar productos");
System.out.println("2. eliminar productos");
System.out.println("3. mostrar productos");
System.out.println("4. ordenar productos");
System.out.println("5. Exit");
System.out.print("ingrese opcion ");
choice = sIn.nextLine();
// Call the appropriate method for the choice selected.
switch (choice) {
case "1": // Add items to the Shopping List
System.out.println(addItems(sIn, shoppingList) + " productos se han agregado a la lista .");
break;
case "2": // Delete items from the Shopping List
System.out
.println(deleteItems(sIn, shoppingList) + " productos se han eliminado de la lista .");
break;
case "3": // Show the items in the Shopping List
showItems(shoppingList);
break;
case "4": // Sort the items in the Shopping List
sortItems(shoppingList);
break;
case "5": // Exit the program
System.out.println();
System.out.println("Goodbye");
done = true;
break;
default: // Handles all input that is not between 1-5
System.out.println("Invalido ingrese opciond e menu u (1-5).");
} // End of switch (choice)
} while (!done); // Keep running the program until the user quits
sIn.close();
}// end of main()
public static int addItems(Scanner sIn, ArrayList<String> shoppingList) {
// FIXME: implement the method
sIn = new Scanner(System.in);
boolean continuar = true;
while(continuar) {
System.out.println("Agrege un articulo a la lista y la cantidad o simplemente presione Enter para finalizar ");
String sn = sIn.nextLine();
if (sn.isBlank())
continuar = false;
else {
shoppingList.add((sn));
}
}
return 0;
}// end of method addItems(ArrayList<String>)
public static int deleteItems(Scanner sIn, ArrayList<String> shoppingList) {
// FIXME: implement the method
return 0;
}// end of method deleteItems(ArrayList<String>)
public static void showItems(ArrayList<String> shoppingList) {
// FIXME: implement the method
}// end of method showItems(ArrayList<String>)
public static void sortItems(ArrayList<String> shoppingList) {
// FIXME: implement the method
}// end of method sortItems(ArrayList<String>)
}//
Valora esta pregunta


0