Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i am having an error with a multiple file code in java. please only edit things to fix the errors and not changing my variable

i am having an error with a multiple file code in java. please only edit things to fix the errors and not changing my variable names. here is my error "ShoppingCartManager.java:25: error: variable option is already defined in method printMenu(ShoppingCart)
String option = scnr.next ();
^
ShoppingCartManager.java:42: error: cannot find symbol
Price = scnrInt.nextInt ();
^
symbol: variable scnrInt
location: class ShoppingCartManager
ShoppingCartManager.java:45: error: cannot find symbol
Quantity = scnrInt.nextInt ();
^
symbol: variable scnrInt
location: class ShoppingCartManager
3 errors"
and heres my code
import java.util.Scanner;
public class ShoppingCartManager {
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);
String option = scnr.nextLine();
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);
}
}
}

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

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

Explain the testing process of accounting 2?

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago