Java Tutorial

 
 
 
 
import java.io.*;
import java.util.*;

class  Inventory
{
    static DataInputStream din = new DataInputStream(System.in);
    static StringTokenizer st;
    public static void main(String[] args) throws IOException
    {
           DataOutputStream dos = new DataOutputStream(
                          new    FileOutputStream(\"Invent.txt\"));

           //Reading from the console
           System.out.print(\"Enter code number : \");
           System.out.flush();
           st = new StringTokenizer(din.readLine());
           int code = Integer.parseInt(st.nextToken());

           System.out.print(\"Enter Item : \");
           System.out.flush();
           st =new StringTokenizer(din.readLine());
           int item = Integer.parseInt(st.nextToken());

           System.out.print(\"Enter Cost of Item : \");
           System.out.flush();
           st =new StringTokenizer(din.readLine());
           double cost = new Double(st.nextToken()).doubleValue();

           //Writing to the file Invent.txt
           dos.writeInt(code);
           dos.writeInt(item);
           dos.writeDouble(cost);
           dos.close();

           //processing data from the file
           DataInputStream dis = new DataInputStream( new 
                      FileInputStream(\"Invent.txt\"));
           int codeNumber = dis.readInt();
           int  totalItems = dis.readInt();
           double itemCost = dis.readDouble();
           double totalCost = totalItems * itemCost;

           //Writing to Console
           System.out.println(\"\\nCode Number : \" + codeNumber);
           System.out.println(\"Item cost          : \" + itemCost);
           System.out.println(\"Total Items       : \" + totalItems);
           System.out.println(\"Total Cost         : \" + totalCost);
    }
}

    Related Post:
  1. Program to show an example of Multiple Levels of Inheritance

  2. Even number ,Prime no. ,Factorial of a number

  3. Program to read rollno, marks of sub1,sub2 and sub3 and on basis of that display result

  4. An applet program that displays Text at the center of the string which is passed as parameter

  5. Program to show an example of Calling a Base Class Method from a Derived Class

  6. Pass the marks of 10 students from the client side design a servlet, which takes these marks and returns the number of students who obtained first cls

  7. An application that combines several classes and interface

  8. Program to show the use of Conditional OR Operator (||) in If Statements

  9. File handling program to count number of characters in a file

  10. An applet program to display alternate filled and empty circle that to in row and column format

  11. Corba program of reverse string

  12. Program to declare, initialize and print an array of characters

  13. Corba program to Write a Echo server and client with UDP server and client

  14. An applet program showing Clicked Event on canvas

  15. Program to show insertion of StringBuffer, String objects and other Basic Data Types into a StringBuffer object

  16. Define an array of ten String elements each containing an arbitrary string of the form “month/day/year”

  17. Program to search an element in an array using Linear Search

  18. Program to show the use of Conditional AND Operator (&&) in If Statements

  19. An applet program to draw Polygon Graph with given data

  20. Program to evaluate following investment equation V=P(1+R)^N

 
 
Didn't find what you were looking for? Find more on Program of inventory management and demonstrating interactive input and output