Saturday 17 September 2011

EX 7


6. Design classes for Currency, Rupee, and Dollar. Write a program that randomly
generates Rupee and Dollar objects and write them into a file using object
serialization. Write another program to read that file, convert to Rupee if it reads a
Dollar, while leave the value as it is if it reads a Rupee.

ALGORITHM FOR PROGRAM 1:
STEP 1:  Create a class named currency that implements the serializable interface and
                also it is the base class for rupee and dollar classes.
STEP 2:  Create an object for ObjectOutputStream to open a file in write mode using
                FileOutputStream.
STEP 3:  Read the user choice to enter rupee or dollar amount.
STEP 4:  Generate random numbers as the value of rupee or dollar.
STEP 5:  If choice is rupee then, append "Rs" to the value generated, else if choice is
                 dollar append "$" to the value generated.
STEP 6: Display the appended String and also write it into the file opened using the
                writeObject() method.
STEP 7: Close the file.
ALGORITHM FOR PROGRAM 2:
STEP 1: Create a class named currency that implements the serializable interface and
               also it is the base class for rupee and dollar classes.
STEP 2: Create an object for ObjectInputStream to open the file created in program1 in
               read mode using FileInputStream.
STEP 3: If the file does not exist or if it is empty show exceptions.
STEP 4: While the End of file is not reached, do the following...
       (i) If the value read is a dollar convert into rupee and print to the user otherwise  
                 print the rupee as such.
STEP 5: End the program.

0 comments:

Post a Comment