Page 357 - computer science (868) class 11
P. 357
dout.writeInt(productC);
dout.writeUTF(productN);
dout.writeDouble(price);
dout.writeInt(quantity);
dout.writeInt(reorder);
}
}
catch(EOFException e)
{
System.out.println("=======EOF=========");
eof=true;
}
din.close();fin.close();
dout.close();fout.close();
// Deleting Product.dat and renaming Newproduct.dat as Product.dat
File f1=new File("Product.dat");
f1.delete();
File f2=new File("Newproduct.dat");
boolean b=f2.renameTo(f1);
if(b)
System.out.println("File renamed successfully");
else
System.out.println("File error");
}
public static void main()throws IOException
{
Scanner sc=new Scanner(System.in);
Stock ob=new Stock();
int ch;
ob.createFile();
ob.printRec();
// Menu to call methods
do{
System.out.println("1. Buy item in stock");
System.out.println("2. Sell item from stock");
System.out.println("3. Edit item price");
System.out.println("4. Print items to order");
System.out.println("5. Remove item from stock");
System.out.println("6. Exit");
System.out.println("Enter option(1 - 6 )");
ch=sc.nextInt();
switch(ch)
{
case 1:
ob.addItem();
ob.printRec();
break;
case 2:
ob.sellItem();
ob.printRec();
break;
355
Basic Input/Output 355

