Create Sequential File Program Aim
Create Sequential File Program Aim
NO:10
DATE:
CREATE SEQUENTIAL FILE PROGRAM
AIM:
Write a Java Program to create a sequential file that could store details
about five products. Details include product code, cost, and number of items
available and are provided through the keyboard. Compute and print the total
value of all the five products.
PROCEDURE:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Step 9:
PROGRAM:
import java.io.*;
import java.util.*;
class Stock
{
static DataInputStream dis=new DataInputStream(System.in);
static StringTokenizer st;
public static void main(String args[])throws IOException
{
FileOutputStream fos=new FileOutputStream("invent.txt");
DataOutputStream dos=new DataOutputStream(fos);
int n=5;
for(int i=1;i<=n;i++)
{
System.out.println("Product: "+i);
System.out.println("Enter Code Number");
st=new StringTokenizer(dis.readLine());
int code=Integer.parseInt(st.nextToken());
dos.writeInt(code);
System.out.println("Enter Number of items");
st=new StringTokenizer(dis.readLine());
int items=Integer.parseInt(st.nextToken());
dos.writeInt(items);
System.out.println("Enter Cost");
st=new StringTokenizer(dis.readLine());
double cost=new Double(st.nextToken()).doubleValue();
dos.writeDouble(cost);
}
dos.close();
System.out.println();
System.out.println("Total Cost" +totalcost);
}
}
OUTPUT:
RESULT:
Thus the above program has been successfully created and verified.