Can i get help with this java code 1 The GUI Create a class
Can i get help with this java code?
(1) The GUI Create a class called ShoppingListApp which will construct the GUI shown below. You should make the window to be non-resizable. You may have to tweak the size a little bit in order to get the bordering margins correct. 10 10 200 120 2000 10 15 65 100 10 CA Grocery Store Application 10 opping Cart roducts 35 300 10 otal Price 25 Buy Return Checkout 10 (2) When the Window First Opens When the window first opens, it should appear (1) with all buttons disabled, (2) the Products list populated with items, (3) the Shopping Cart and Contents lists should be empty and (4) the Total Price should appear as $0.00, aligned to the right side of the text field and properly formatted.Solution
package cart;
import entity.Product;
import java.util.*;
public class ShoppingCart {
List<ShoppingCartItem> items;
int numberOfItems;
double total;
public ShoppingCart() {
items = new ArrayList<ShoppingCartItem>();
numberOfItems = 0;
total = 0;
}
public synchronized void addItem(Product product) {
boolean newItem = true;
for (ShoppingCartItem scItem : items) {
if (scItem.getProduct().getId() == product.getId()) {
newItem = false;
scItem.incrementQuantity();
}
}
if (newItem) {
ShoppingCartItem scItem = new ShoppingCartItem(product);
items.add(scItem);
}
}
public synchronized void update(Product product, String quantity) {
short qty = -1;
qty = Short.parseShort(quantity);
if (qty >= 0) {
ShoppingCartItem item = null;
for (ShoppingCartItem scItem : items) {
if (scItem.getProduct().getId() == product.getId()) {
if (qty != 0) {
scItem.setQuantity(qty);
} else {
item = scItem;
break;
}
}
}
if (item != null) {
items.remove(item);
}
}
}
public synchronized List<ShoppingCartItem> getItems() {
return items;
}
public synchronized int getNumberOfItems() {
numberOfItems = 0;
for (ShoppingCartItem scItem : items) {
numberOfItems += scItem.getQuantity();
}
return numberOfItems;
}
public synchronized double getSubtotal() {
double amount = 0;
for (ShoppingCartItem scItem : items) {
Product product = (Product) scItem.getProduct();
amount += (scItem.getQuantity() * product.getPrice().doubleValue());
}
return amount;
}
public synchronized void calculateTotal(String surcharge) {
double amount = 0;
double s = Double.parseDouble(surcharge);
amount = this.getSubtotal();
amount += s;
total = amount;
}
public synchronized double getTotal() {
return total;
}
public synchronized void clear() {
items.clear();
numberOfItems = 0;
total = 0;
}
}


