Create a Java application with a class that describes a product. The product should have a name, an identification number, a price, and a quantity ordered. You may have other data as well, if you want. The class should have a method that reads in the data and another that displays it. The one that displays the data should also compute the total value, i.e. the price times the quantity.
import java.io.*;
import java.text.*;
// An application that displays information about a product.
public class ProductOrder
{
public static void main (String []
args)
{
Product theProduct
= new Product ();
theProduct.getProduct
();
theProduct.displayProduct
();
} // method main
} // public class ProductOrder
class Product
{
private String name, id;
private double price;
private int quantity;
public void getProduct ()
{
// Use the
methods found in the Reader class to read in the name, id, price, and quantity.
} // method getProduct
public void displayProduct ()
{
// Display
on the screen all the information about the product.
// Then calculate
the price times the quantity and display that also.
} // method displayProduct
} // class Product
class Reader
{
// Reads a double from the keyboard
and returns it to the calling method.
public static double readDouble ()
{
double num;
BufferedReader
stdin = new BufferedReader (new InputStreamReader (System.in));
try
{
num = Double.valueOf (stdin.readLine ()).doubleValue ();
} catch (IOException
e) { num = 0;}
return num;
} // private static double readDouble
()
// Formats a double for string output
with two decimal places.
public static String decimals (double
num)
{
DecimalFormat
decFor = new DecimalFormat ();
decFor.setMaximumFractionDigits
(2);
decFor.setMinimumFractionDigits
(2);
return decFor.format
(num);
} // private String decimals (double
num)
// Reads an integer from the keyboard
and returns it to the calling method.
public static int readInteger ()
{
int num;
BufferedReader
stdin = new BufferedReader (new InputStreamReader (System.in));
try
{
num = Integer.parseInt (stdin.readLine ());
} catch (IOException
e) { num = 0;}
return num;
} // public static int readInteger
()
// Reads a string from the keyboard
and returns it to the calling method.
public static String readString ()
{
String str;
BufferedReader
stdin = new BufferedReader (new InputStreamReader (System.in));
try
{
str = stdin.readLine ();
} catch (IOException
e) { str = "";}
return str;
} // public static int readString
()
} // public class Reader