please send me answer within 10 min!! i will rate you good for sure!! Please provide explaination!! 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("\nItem 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("\nTOTAL 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("\nTotal: " + ((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
please send me answer within 10 min!! i will rate you good for sure!! Please provide explaination!!
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("\nItem 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("\nTOTAL 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("\nTotal: " + ((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
Solved in 3 steps with 3 images