Challenge

Project 1

Example Output:

1. Customer

2. Seller

3. Admin

Also I have handled the exception

try {

Product[] cartProducts = current.getCart().getListOfProducts();

// System.out.println("Inside Try Block");

if(cartProducts.length > 0) {

for (int i = 0; i < cartProducts.length; i++) {

System.out.println(cartProducts[i].getProductId() + " "

+ cartProducts[i].getProductName() + " " + cartProducts[i].getCost());

}

}

else {

throw new NullPointerException();

}

}

catch(NullPointerException e) {

System.out.println("Your cart is empty!");

continue;

}

Note: If we don't handle this exception, if the user type 2 without adding the products

to the cart then it will throw NullPointerException.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.