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. An applet program that displays random dot

  2. File handling program to copy characters from one file to another

  3. An applet program to draw circle in center of the canvas

  4. Program to show the use of operator (>>) Shift Right, propagating the sign bit from the left

  5. CORBA program for displaying the date and time of the server machine, client machine and the difference between these two date and time

  6. Program to show an example of using multiple classes in a program

  7. Program to show the use of Comparison operator (==) for comparing Strings

  8. An applet program to take user input and display

  9. Program that takes a long sentence and a character from the client and count the occurrence of the character in the sentence at the server side

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

  11. Program of linear search

  12. Program to show the use of Bitwise Operator (|) OR

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

  14. Program to determine the sum of the following harmonic series for a given value of n

  15. Do the following for the Array Insert the element in the array,delete an element from the array,search for a particular element Create multiple thread

  16. Program to find a factorial of a given number

  17. Program to show an example of using Abstract Class and Abstract Method

  18. Program which simulate the dictionary in java

  19. Even no or Prime no?????

  20. Program to append a StringBuffer by StringBuffer, String objects and other Basic Data Types

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