Im trying to make a code that similar to this removeMenu method but I want to make another method that updates the quantity of the product in the menu i've ordered.
Code for restaurant controller:
Menu coffee = new Menu("Coffee", 30);
Menu icedTea = new Menu("Iced Tea", 50);
Menu hotChoco = new Menu("Hot Chocolate", 30);
/*
constructor ommittet.
*/
private ArrayList<Menu> menulist;
public void removeMenu(Menu menumodel) {
for (Menu temp : menulist) {
if (temp.equals(menumodel)) {
menulist.remove(temp);
break;
}
}
}
public void updateMenu(int updateQuant) {
//menulist.set(3, updateQuant);
}
}
}
Restaurant class
RestaurantController controller1 = new RestaurantController();
private void DeleteProductActionPerformed(java.awt.event.ActionEvent evt) {
selectedProduct = controller1.getMenulist().get(JTableOrderReceived.getSelectedRow());
if (selectedProduct != null) {
int ans = JOptionPane.showConfirmDialog(this, "The selected product will be removed! ", "DELETE PRODUCT", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (ans == JOptionPane.YES_OPTION) {
controller1.removeMenu(selectedProduct);
refTable();
}
}
}
private void UpdateProduct(java.awt.event.ActionEvent evt) {
selectedProduct controller1.getMenulist().get(JTableOrderReceived.getSelectedRow());
if (selectedProduct != null) {
int parseQuant = (int) selectedProduct.getQuantity();
String uQuant = JOptionPane.showInputDialog(this, "Update quantity " + selectedProduct.getItemName() + "\nPrice: " + selectedProduct.getPrice() + "\nCurrent order: " + parseQuant);
int nQuant = Integer.parseInt(uQuant);
controller1.updateMenu(nQuant);
refTable();
}
}
Im having problems on the updateMenu method in restaurant controller class, can anyone help on how to?