Name: Anonymous 2007-04-10 17:53 ID:afRMT8dH
See, it works like it should until the end of the loop, but it just prints "Add another item? (y/n)." and then terminates. Why isn't it prompting for input?
Yeah Java sucks, great, that doesn't change the fact that I'm enrolled in a Java class.
Yeah Java sucks, great, that doesn't change the fact that I'm enrolled in a Java class.
import java.util.Scanner;
public class Shopping
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
ShoppingCart cart = new ShoppingCart();
String another = "y";
String item;
double price;
int quantity;
while (another.equalsIgnoreCase("y"))
{
System.out.println ("What item are you adding to your cart?");
item = scan.nextLine();
System.out.println ("What is the unit cost of " + item + "?");
price = scan.nextDouble();
System.out.println ("What quantity of " + item + " are you buying?");
quantity = scan.nextInt();
cart.addToCart (item, price, quantity);
System.out.print (cart);
System.out.print ("\nAdd another item? (y/n).");
another = scan.nextLine();
}
}
}