Page 353 - computer science (868) class 11
P. 353

DataInputStream din=new DataInputStream(fin);
                               boolean eof=false;
                               System.out.println("Place order for the following products");
                               System.out.println("Product code\tProduct name\tQuantity\tReorder");
                               try
                               {
                                   while(!eof)  // reading the records in the file
                                   {
                                       productC = din.readInt();
                                       productN = din.readUTF();
                                       price =din.readDouble();
                                       quantity = din.readInt();
                                       reorder = din.readInt();
                                       if(quantity<reorder)   // if quantity in stock < reorder level
                                           System.out.println(productC+"\t\t"+productN+"\t\t"+quantity+"\t\
                          t"+reorder);
                                   }
                               }
                               catch(EOFException e)
                               {
                                   System.out.println("==============================================");
                                   eof=true;
                               }
                               din.close();
                               fin.close();
                           }
                           void editPrice() throws IOException
                           {
                               FileOutputStream fout=new FileOutputStream("Newproduct.dat");
                               DataOutputStream dout=new DataOutputStream(fout);
                               FileInputStream fin=new FileInputStream("Product.dat");
                               DataInputStream din=new DataInputStream(fin);
                               int ino;
                               double pr;
                               System.out.println("Enter item number to edit");
                               ino=sc.nextInt();
                               System.out.println("Enter changed price");
                               pr=sc.nextDouble();
                               boolean eof=false;
                               try
                               {
                                   while(!eof)  // reading records in the file Product.Dat
                                   {
                                       productC=din.readInt();
                                       productN=din.readUTF();
                                       price=din.readDouble();
                                       quantity=din.readInt();
                                       reorder=din.readInt();
                                       if(productC==ino)   // if product code match
                                       price=pr;            // price is changed
                                       // writing the records in the file Newproduct.dat


                                                                                                                       351
                                                                                                    Basic Input/Output   351
   348   349   350   351   352   353   354   355   356   357   358