Page 378 - Cs_withBlue_J_C11_Flipbook
P. 378
productC=sc.nextInt();
System.out.println("Enter product name");
productN=sc.next();
sc=new Scanner(System.in);
System.out.println("Enter product price");
price=sc.nextDouble();
System.out.println("Enter quantity in stock");
quantity=sc.nextInt();
System.out.println("Enter re order level");
reorder=sc.nextInt();
dout.writeInt(productC);
dout.writeUTF(productN);
dout.writeDouble(price);
dout.writeInt(quantity);
dout.writeInt(reorder);
System.out.println("Continue y/n");
ch=sc.next().charAt(0);
}
dout.close();
fout.close();
}
void printRec() throws IOException
{ // printing the records in the file
FileInputStream fin=new FileInputStream("Product.dat");
DataInputStream din=new DataInputStream(fin);
boolean eof=false;
System.out.println("Product code\tProduct name\tPrice\tQuantity\tReorder");
try
{
while(!eof)
{
productC = din.readInt();
productN = din.readUTF();
price = din.readDouble();
quantity = din.readInt();
reorder = din.readInt();
System.out.println(productC+"\t\t"+productN+"\t\t"+
price+"\t"+quantity+"\t\t"+reorder);
}
}
catch(EOFException e)
{
System.out.println("==============================================");
eof=true;
}
din.close();
fin.close();
}
void printReorder() throws IOException
{
FileInputStream fin=new FileInputStream("Product.dat");
376376 Touchpad Computer Science-XI

