Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i am having a error in java that i do not know what it means, its multiple files. this is the error message Exception in

i am having a error in java that i do not know what it means, its multiple files. this is the error message "Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1478)
at ShoppingCartManager.printMenu(ShoppingCartManager.java:31)
at ShoppingCartManager.main(ShoppingCartManager.java:115)"
this is my first file
import java.util.Scanner;
public class ShoppingCartManager {
//Implement the printMenu() method. printMenu() has a ShoppingCart parameter,
// and outputs a menu of options to manipulate the shopping cart.
// Each option is represented by a single character. Build and output the menu within the method.
public static void printMenu(ShoppingCart shoppingCart){
System.out.println ("
MENU");
System.out.println ("a - Add item to cart");
System.out.println ("d - Remove item from cart");
System.out.println ("c - Change item quantity");
System.out.println ("i - Output items' descriptions");
System.out.println ("o - Output shopping cart");
System.out.println ("q - Quit");
System.out.println ("
Choose an option:");
Scanner scnr = new Scanner (System.in);
Scanner scnrInt = new Scanner (System.in);
// Declare a new item to purchase.
ItemToPurchase item = new ItemToPurchase ();
String Name ="";
String Description ="";
int Price =0;
int Quantity =0;
String option = scnr.next ();
scnr.nextLine();
switch(option.charAt (0)){
case 'a':
System.out.println ("
ADD ITEM TO CART");
scnr = new Scanner (System.in);
System.out.println ("Enter the item name:");
Name = scnr.nextLine ();
System.out.println ("Enter the item description:");
Description = scnr.nextLine ();
System.out.println ("Enter the item price:");
Price = scnrInt.nextInt ();
System.out.println ("Enter the item quantity:");
Quantity = scnrInt.nextInt ();
item = new ItemToPurchase (Name, Description, Price,
Quantity);
shoppingCart.addItem (item);
printMenu (shoppingCart);
break;
case 'd':
System.out.println ("REMOVE ITEM FROM CART");
System.out.println ("Enter name of item to remove:");
scnr.nextLine ();
String itemName = scnr.nextLine ();
shoppingCart.removeItem (itemName);
printMenu (shoppingCart);
break;
case 'c':
System.out.println ("CHANGE ITEM QUANTITY");
System.out.println ("Enter the item name:");
scnr.nextLine ();
itemName = scnr.nextLine ();
shoppingCart.modifyItem (itemName);
printMenu (shoppingCart);
break;
case 'i':
System.out.println ("OUTPUT ITEM'S DESCRIPTIONS");
shoppingCart.printDescriptions ();
printMenu (shoppingCart);
break;
case 'o':
System.out.println ("OUTPUT SHOPPING CART");
shoppingCart.printTotal ();
printMenu (shoppingCart);
break;
default:
System.out.println ("Invalid Choice!");
printMenu (shoppingCart);
}
System.out.println ("
");
}
public static void main (String[]args){
{
Scanner scnr = new Scanner (System.in);
System.out.println ("Enter customer's name:");
String customerName = scnr.nextLine ();
System.out.println ("Enter today's date:");
String currentDate = scnr.nextLine ();
System.out.println ("
Customer name: "+ customerName);
System.out.println ("Today's date: "+ currentDate);
// Create a linked list shopping cart.
ShoppingCart shoppingCart = new ShoppingCart (customerName, currentDate);
// Print menu.
printMenu (shoppingCart);
}
}
}
its too many character to add them all can you figure it out with this information?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

ISBN: 0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago