Page 379 - Cs_withBlue_J_C11_Flipbook
P. 379

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


                                                                                                                       377
                                                                                 Basic Input/Output and Data File Handling    377
   374   375   376   377   378   379   380   381   382   383   384