0% found this document useful (0 votes)
65 views

Create Sequential File Program Aim

The document describes a Java program to create a sequential file that stores product details like code, cost, and quantity for five products entered through keyboard. It writes the details to an output file, then reads from the file to display the details and calculate the total value. The program takes product details as input, writes it to a file, reads from the file and displays the details along with total cost.

Uploaded by

Anand Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Create Sequential File Program Aim

The document describes a Java program to create a sequential file that stores product details like code, cost, and quantity for five products entered through keyboard. It writes the details to an output file, then reads from the file to display the details and calculate the total value. The program takes product details as input, writes it to a file, reads from the file and displays the details along with total cost.

Uploaded by

Anand Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EX.

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 1: Start the Program.

Step 2:

Step 3:

Step 4:

Step 5:

Step 6:

Step 7:

Step 8:

Step 9:

Step 10: Stop the program.

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();

FileInputStream fis=new FileInputStream("invent.txt");


DataInputStream dis=new DataInputStream(fis);
double totalcost=0;;
for(int i=1;i<=n;i++)
{
int codenumber=dis.readInt();
System.out.println();
System.out.println("Product: "+i);
System.out.println("CodeNumber : "+codenumber);
int totalitems=dis.readInt();
System.out.println("Total Items:" +totalitems);
double itemcost=dis.readDouble();
System.out.println("ItemCost:" +itemcost);
totalcost+=totalitems*itemcost;
}
dis.close();

System.out.println();
System.out.println("Total Cost" +totalcost);
}
}

OUTPUT:
RESULT:
Thus the above program has been successfully created and verified.

You might also like