A good answer might be:

Yes. It is a little awkward, however, because the user prompts as well as the computed answer will be sent to the output text file.

All Output gets sent to a File

Here is an example of redirecting the output of this file. Notice that the user does not see any prompts because they have been sent to the output file:

C:\users\default\JavaLessons>java Discount > discount.out

100
20

C:\users\default\JavaLessons>type discount.out
Enter list price in cents:
Enter discount in percent:
Discount Price: 80

C:\users\default\JavaLessons>

Of course the output file does not get any of the characters that the user typed because they were sent to the program. To deal with this problem, programs are sometimes written to echo all user input:

import java.io.*;
class Discount
{
  public static void main ( String[] args ) throws IOException
  {
    int listPrice;
    int discount;
    int discountPrice;

    String line;
    BufferedReader stdin = new BufferedReader( 
        new InputStreamReader( System.in ) );

    System.out.println("Enter list price in cents:");
    line = stdin.readLine();
    listPrice = Integer.parseInt( line );
    System.out.println("List price:" + line );    // echo input

    System.out.println("Enter discount in percent:");
    line = stdin.readLine();
    discount = Integer.parseInt( line );
    System.out.println("Discount:" + line );      // echo input

    discountPrice = listPrice - (listPrice*discount)/100 ;
    System.out.println( "Discount Price: " + discountPrice );
  }
}


QUESTION 11:

Is it a mistake that the echo lines use the variable line instead of the variables listPrice and discount?