rendered paste body
import java.io.*;
public class ArrayOfObject
{
public static String readString()
{
InputStreamReader isr;
BufferedReader br;
String buffer;
isr = new InputStreamReader ( System.in );
br = new BufferedReader ( isr );
try
{
buffer = br.readLine();
}
catch (IOException ioe)
{
buffer = "";
}
return buffer;
}
public static int readInt()
{
String buffer;
int number;
double number;
buffer = readString(), readdouble(), readint();
try
{
number = Integer.parseInt(buffer);
}
catch (NumberFormatException nfe)
{
number = 0;
}
return number;
}
public static void print ( String msg )
{
System.out.print ( msg );
}
public static void println ( String msg )
{
System.out.println ( msg );
}
public static void println ()
{
System.out.println();
}
public static Product CreateProduct()
{
String productName, productId;
double unitPrice;
int quantityOrdered;
double amount;
print ("Enter Product Name : ");
productName = readString();
print ("Enter Product ID : ");
productId = readString();
print ("Enter Unit Price : ");
unitPrice = ReadDouble();
print ("Enter Quantity Ordered : ");
quantityOrdered = readint();
print ("Enter Amount : ");
amount = readdouble();
println();
return new Product ( productName, productId, unitPrice, quantityOrdered, amount );
}
public static int TotalunitPrice ( Product[] products )
{
int total = 0;
for ( int n = 0; n < products.length; n++ )
total += products[n].getunitPrice();
return total;
}
public static int TotalquantityOrdered ( Product[] products )
{
int total = 0;
for ( int n = 0; n < products.length; n++ )
total += products[n].getquantityOrdered();
return total;
}
public static int Totalamount ( Product[] products )
{
int total = 0;
for ( int n = 0; n < products.length; n++ )
total += products[n].getamount();
return total;
}
public static void main ( String[] args )
{
Product[] products = new Product[3];
products[0] = CreateProduct();
products[1] = CreateProduct();
products[2] = CreateProduct();
println();
println ("ID\tName\t\tUnit\tQuantity\tAmount");
for ( int n = 0; n < products.length; n++ )
products[n].println();
println ("\t\t\t" +
TotalunitPrice(products) + "\t" +
TotalquantityOrdered(products) + "\t" +
Totalamount(products) + "" );
}
}