Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help i have my java code all written out but it wont print anything after the second price? it just keeps giving me

I need help i have my java code all written out but it wont print anything after the second price? it just keeps giving me an exception of main InputMismatchException?

////////. 1/2 files

import java.util.Scanner;

public class ShoppingCartPrinter { public static void main(String[] args) { Scanner scnr = new Scanner(System.in);

/* Type your code here. */ String name; int price = 0; int quantity = 0; ItemToPurchase item1 = new ItemToPurchase(); ItemToPurchase item2 = new ItemToPurchase(); System.out.println("Item 1"); System.out.println("Enter the item name:"); name = scnr.nextLine(); item1.setName(name); System.out.println("Enter the item price:"); price = scnr.nextInt(); item1.setPrice(price); System.out.println("Enter the item quantity:"); quantity = scnr.nextInt(); item1.setQuantity(quantity); //System.out.println(); System.out.println(" Item 2"); System.out.println("Enter the item name:"); name = scnr.nextLine(); item2.setName(name); System.out.println("Enter the item price:"); price = scnr.nextInt(); item2.setPrice(price); System.out.println("Enter the item quantity:"); quantity = scnr.nextInt(); item2.setQuantity(quantity); //System.out.println(); System.out.println(" TOTAL COST"); System.out.println(item1.getName() + " " + item1.getQuantity() + " @ $" + item1.getPrice() + " = $" + (item1.getPrice() * item1.getQuantity())); System.out.println(item2.getName() + " " + item2.getQuantity() + " @ $" + item2.getPrice() + " = $" + (item2.getPrice() * item2.getQuantity())); System.out.println(" Total: " + ((item1.getPrice() * item1.getQuantity()) + (item2.getPrice() * item2.getQuantity()))); }//end of main }//end of class ShoppingCartPrinter

////. 2/2 file

public class ItemToPurchase{ private String itemName; private int itemPrice; private int itemQuantity; public ItemToPurchase(){ }//end of ItemToPurchase public String getName(){ return itemName; }//end getName public void setName(String itemName){ this.itemName = itemName; }//end itemName public int getPrice(){ return itemPrice; }//end getPrice public void setPrice(int itemPrice){ this.itemPrice = itemPrice; }//end setPrice public int getQuantity(){ return itemQuantity; }//end getQuatity public void setQuantity(int itemQuantity){ this.itemQuantity = itemQuantity; }//end setQuantity }//end class ItemToPurchase

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

Icdt 88 2nd International Conference On Database Theory Bruges Belgium August 31 September 2 1988 Proceedings Lncs 326

Authors: Marc Gyssens ,Jan Paredaens ,Dirk Van Gucht

1st Edition

3540501711, 978-3540501718

More Books

Students also viewed these Databases questions

Question

=+31-4 Discuss the information we process automatically.

Answered: 1 week ago

Question

Include a retrosynthetic analysis for each synthetic scheme. OH

Answered: 1 week ago