Looping in Java Course Homework will not work
<p>I am having issues with a problem that I coded for a Java course I am taking, and I cannot figure out why it is behaving a certain way. Here is the problem form the book, both part A and part B:</p>

<p>A) Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set() method for the sale amount, calculate the sales tax as 5% of the sale amount. Also include a display method that displays a purchase's details. Save the file as Purchase.java</p>

<p>B) Create an application that declares a Purchase object and prompts the user for purcase details. When you prompt for an invoice number, do not let the user proceed untial a number between 1000 and 8000 has been entered. When you prompt for a sale amount, do not proceed until the user has entered a non-negative number, sale amount, and sales tax. Save the file as CreatePurchase.java.</p>

<p>Here is the code for the first part of the problem:</p>

<pre><code>public class Purchase
{

    int invoiceNumber = 1234;
    double salePrice = 10.00;
    double SalesTax;

    public void setInvoiceNumber(int invoice)
    {
        invoiceNumber = invoice;
    }

    public void setSalePrice(double saleAmount)
    {
        salePrice = saleAmount;
        SalesTax = (saleAmount * .05);
    }

    public void displaySalePrice()
    {
        System.out.println("Your invoice number is:" + invoiceNumber + ".");
        System.out.println("Your sale amount is: " + salePrice + ".");
        System.out.println("Your sales tax is: " + SalesTax + ".");
    }

 }
</code></pre>

<p>Here is the code for the second part of the problem:</p>

<pre><code>import java.util.Scanner;

public class CreatePurchase
{
    public static void main(String[] args)
    {

        int invoice;
        double saleAmount;
        invoice = 0;
        saleAmount = 0.0;
        Purchase completedPurchase = new Purchase();

        Scanner input = new Scanner(System.in);
        System.out.println("Please enter the invoice number: ");
        invoice = input.nextInt();
        System.out.println("Please enter the sale amount: ");
        saleAmount = input.nextDouble();

        do
        {
            System.out.println("You entered an invalid number.");
            System.out.println("Please enter a number between 1000 and 8000.");
            invoice = input.nextInt();
        }   
        while (invoice &lt; 1000 || invoice &gt; 8000);

        do
        {
            System.out.println("You entered an invalid number."); 
            System.out.println("Please enter a number greater than 0.");
            saleAmount = input.nextDouble();
        }
        while (saleAmount &lt; 0);

        completedPurchase.setInvoiceNumber(invoice);
        completedPurchase.setSalePrice(saleAmount);

        completedPurchase.displaySalePrice();
    }
}
</code></pre>

<p>When I complie CreatePurchase.java and run it, it works, but has to cycle through the loops first before it works. For instance, I will type in <code>7000</code> for the invoice value and <code>100</code> for the sale amount. Those two values should automatically call the <code>completePurchase.displaySalePrice();</code> method because the invoice number is greater than <code>1000</code> and less than <code>8000</code>, and the sale amount is greater than <code>0</code>. That being the case, it still cycles through the do while loops once before calling that method.</p>

<p>I cannot for the life of me figure this out. It's probably something pretty simple I am missing. Any help would be greatly appreciated.</p>

<p>After the great guidance of everyone below, I changed the code for the loops to the following:</p>

<pre><code>while (invoice &lt; 1000 || invoice &gt; 8000)
        {
            System.out.println("You entered an invalid number.");
            System.out.println("Please enter a number between 1000 and 8000.");
            invoice = input.nextInt();
        }   

        while (saleAmount &lt; 0)
        {
             System.out.println("You entered an invalid number."); 
             System.out.println("Please enter a number greater than 0.");
             saleAmount = input.nextDouble();
        }
</code></pre>

<p>It still isn't working correctly. Changing the loops to while loops certainly worked, but now when I enter a number for the invoice number that's in the correct range and an incorrect number for the saleAmount, the program finished and does not execute the while loop for saleAmount? I seem to be missing a concept here.</p>

<p>Also, can anyone recommend a better IDE than JGrasp. That is what we were told to use, but it's cumbersome. I have VisualStudio and Eclipse, but I feel that doing java homework in those two IDE's might be overkill. I will be taking more java courses and c++ courses, so maybe it's worth learning the basics in VS or Eclipse. Any suggestions would be appreciated.</p>
