Java: Storing a selected value for later use
<p>What I need help with is this, I am learning Jave by creating the below simple sales calculator. I have a section within this code as follows:</p>

<pre><code>System.out.println ("Please make a selection:");
System.out.println ("1. Octopus Tentacles, 2. Rat Droppings");
System.out.println ("3. Sharks teeth, 4. Mountain Oysters");
System.out.println (" ");
// Since we don't have a primary database to pull from we use a dummy DB
while ( foodCount &lt;= 1 )
{
System.out.print( "Enter selection (1 , 2, 3, 4): ");
result = input.nextInt();

if ( result == 1)
    System.out.println( "You selected Octopus tentacles, price $4.99" );
else if ( result == 2)
    System.out.println( "You selected Rat droppings, price $3.49" );
else if ( result == 3)
    System.out.println( "You selected Sharks teeth, price $6.73" );
else if ( result == 4)
    System.out.println( "You selected Mountain Oysters, price $9.95" );
break;
}

System.out.println (" ");
</code></pre>

<p>it allows a selection to me made, what I want to do is have that value stored for use in the Price input section alittle below that. Can someone help me please? I am new to Java and learning my way through my own walks of reading books searching the internet but havent found anything that will help me in this instance. Any assistance with this would be appreciated.</p>

<hr>

<pre><code>import java.io.*;
import java.text.*;
import java.util.*;
import java.util.Scanner;
import java.math.BigDecimal;
import java.text.NumberFormat;

class priceCalc {

public static void main (String[] args) throws IOException {
  BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
  Scanner input = new Scanner(System.in);
  int Quantity;
  int result = 0;
  int foodCount = 1;
  double Price, Subtotal, SalesTax, TotalSale;
  NumberFormat curForm = NumberFormat.getCurrencyInstance();
// Here is a simple display of available products
  System.out.println (" ");
  System.out.println ("Welcome to the IP2 part 2!");
  System.out.println (" ");

  System.out.println ("Please make a selection:");
  System.out.println ("1. Octopus Tentacles, 2. Rat Droppings");
  System.out.println ("3. Sharks teeth, 4. Mountain Oysters");
  System.out.println (" ");
// Since we don't have a primary database to pull from we use a dummy DB
  while ( foodCount &lt;= 1 )
  {
  System.out.print( "Enter selection (1 , 2, 3, 4): ");
  result = input.nextInt();

  if ( result == 1)
    System.out.println( "You selected Octopus tentacles, price $4.99" );
  else if ( result == 2)
    System.out.println( "You selected Rat droppings, price $3.49" );
  else if ( result == 3)
    System.out.println( "You selected Sharks teeth, price $6.73" );
  else if ( result == 4)
    System.out.println( "You selected Mountain Oysters, price $9.95" );
  break;
  }

  System.out.println (" ");
    // Create Scanner for input
  Scanner key = new Scanner(System.in);

    //Quantity
  System.out.print ("Please enter quantity: ");
  Quantity = key.nextInt();
  System.out.println (" ");

    //Price    
  System.out.print ("Please input price (price amount w/no $): ");
  Price = key.nextDouble();
  System.out.println (" ");

    //Subtotal
  Subtotal = Price * Quantity;
  System.out.println ("Your subtotal is: " +curForm.format(Subtotal));

    //Sales Tax
  SalesTax = Subtotal * .065;
  System.out.println ("Your sales tax is: " +curForm.format(SalesTax));

    //Total Sale
  TotalSale = Subtotal+SalesTax;
  System.out.println ("Your total sale price is: " +curForm.format(TotalSale));
  System.out.println (" ");
}
}
</code></pre>
