Almost got it need something to stop program!
Hey there you all have been a super help. Heres my program. I have it all but how to stop if the user enters -99. I can't seem to figure out that part. Here is the assignment instructions:
Change this program to repeat until you enter a -99 for the quantity. Otherwise verifiy that the quantity is 1-100 inclusive and that the price is $1.00 or more but less than $100.00. If the entry is incorrect, keep repeating the request for that portion of the data until a correct value is entered. Display an error message if the entry is incorrect. Order of data being entered is up to you.
/**
* Loop exercise
* prompt for name of purchase item, quantiy, price,
* calculate the total including tax and display in one line
* continue until -99 error by user.
* @author (Donna Jones)
* @version (April 25th)
*/
import java.util.Scanner;
import java.text.NumberFormat;
public class editpurchase
{
//-----------------------------------------------------------------
// Calculates the total price of items includes quantity, item name
// cost per item, total cost including tax. Edits to tell user of incorrect
// input, printing error message and request re-entry
//-----------------------------------------------------------------
public static void main (String[] args)
{
final double TAX_RATE = 0.06; // 6% sales tax
String Item;
int quantity;
double subtotal,totalcost,unitPrice;
Scanner scan = new Scanner (System.in);
NumberFormat fmt1 = NumberFormat.getCurrencyInstance();
NumberFormat fmt2 = NumberFormat.getPercentInstance();
//PROMPTING FOR USER INPUT
do
{
System.out.print ("Enter the name of your item: ");
Item = scan.next();
do
{
System.out.print ("Enter the quantity: ");
quantity = scan.nextInt();
if (quantity < 0 || quantity >100) //less than zero & greater 100 print out following error message
{ System.out.println ("You've keyed an invalid quantity: Enter number between 1-100");
}
} while (quantity < 0 || quantity >100);
do
{
System.out.print ("Enter the unit price: ");
unitPrice = scan.nextDouble();
if (unitPrice < 1.00 || unitPrice > 99.99) //less than one dollar & 99.99 print out following error message
{ System.out.println ("You've keyed an invalid price: Enter a value between 1.00-99.99 ");
}
} while (unitPrice < 1.00 || unitPrice > 99.99);
System.out.println();
subtotal = quantity * unitPrice;
totalcost = (subtotal *TAX_RATE) + subtotal;
System.out.println ("Item purchased is: " + Item+ ". The quantity purchased was " +quantity
+ " the cost per item was: " +fmt1.format(unitPrice) + " for a subtotal of " + fmt1.format(subtotal)
+ " with a total cost of " + fmt1.format(totalcost));
System.out.println();
}
while (quantity !=-99);
}
}