Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello I am having an error that i dont know how to fix. JAVA The files are being upload to zybooks. Here is my code:

Hello I am having an error that i dont know how to fix. JAVA

image text in transcribed

The files are being upload to zybooks.

Here is my code:

ShoppingCartPrinter.java

import java.util.Scanner;

public class ShoppingCartPrinter {

public static void main(String[] args) {

//creating scanner object for getting input from the keyboard Scanner in=new Scanner(System.in);

//array to store the object ItemToPurchase[] arr=new ItemToPurchase[2];

//variables to store the total, counter int i=0; int total1=0; int total=0;

//getting input from the user for(i=0;i

//getting item name System.out.println("Enter the item name:"); String name=in.nextLine();

//getting item price System.out.println("Enter the item price:"); int price=in.nextInt();

//getting item quantity System.out.println("Enter the item quantity:"); int quantity=in.nextInt();

//creating object arr[i]=new ItemToPurchase(name,price,quantity); in.nextLine(); System.out.println();

}

System.out.println("TOTAL COST");

//calculating the total for(i=0;i

System.out.println(" Total: $"+total);

} }

ItemToPurchase.java

class ItemToPurchase { //variable to store the name,price, quantity private String itemName; private int itemPrice; private int itemQuantity;

//default constructor public ItemToPurchase() { itemName="none"; itemPrice=0; itemQuantity=0; }

//parameterized constructor public ItemToPurchase(String itemname, int price,int quantity) { itemName=itemname; itemPrice=price; itemQuantity=quantity; }

//method to set the name public void setName(String name) { itemName=name; }

//method to set the price public void setPrice(int price) { itemPrice=price; }

//method to set the quantity public void setQuantity(int quantity) { itemQuantity=quantity; }

//method to get the name public String getName() { return itemName; }

//method to get the price public int getPrice() { return itemPrice; }

//method to get the quantity public int getQuantity() { return itemQuantity; } }

thank you

5: Compare output A Output differs. See highlights below. Special character legend Chocolate Chips Input Bottled Water 10 Item 1 Enter the item name: Enter the item price: Enter the item quantity: Item 2 Your output Enter the item name: Enter the item price: Enter the item quantity: Exception in thread "main" java.util.NosuchElementException: No line fou at java.util.Scanner.nextLine (Scanner.java:1540) ?at ShoppingCartPrinter.main (ShoppingCartprinter.java:52) Item 1 Enter the item name: Enter the item price: Enter the item quantity: Item 2 Enter the item name: Expected output Enter the item price: Enter the item quantity: TOTAL cosT chocolate Chips 1 @ $3 = $3 Bottled Water 10 s1 $10e Total: $13

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

How does clustering in unsupervised learning help in data analysis?

Answered: 1 week ago

Question

=+ What about the use of language and the tone of the text?

Answered: 1 week ago

Question

=+a. Describe the mistakes made by the writers of this message.

Answered: 1 week ago