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 modifying String objects

  2. Program to declare, initialize and print an array of integers

  3. Application for counting factorial of a given number

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

  5. Program to show an example of Concatination of Strings

  6. Program to reverse the number eg given no : - 12345, output want :- 54321

  7. Program to display attributes of a specified file

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

  9. Program to print some text on the same line using multiple print statements

  10. An applet program to display text

  11. Develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side, executed on server

  12. Program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01

  13. An applet program of linear sort

  14. Corba program to develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side

  15. Program of binary search tree

  16. Program to show an example of using initialization block to initialize the data members of a class

  17. Program to represent a bank account

  18. Program to show an example of using constructors in a class to initialize its data members

  19. Program in CORBA which takes a long sentence from client (at least 7 words), passes to the server, server separates out each word and sends back

  20. Program to show the use of Break Statement

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