// Doller to Rupee program by WHITMAN KUMARESH for my sister DHANA
// Two progs are there execute write program first and then the read prog
// Any Queries ->
[email protected]FIRST PROG - WRITE PROGRAM
import java.io.*;
import java.util.*;
class Currency implements Serializable {
protected String currency;
protected int amount;
public Currency(String cur, int amt) {
this.currency = cur;
this.amount = amt;
}
public String toString() {
return currency + amount;
}
public String dollarToRupee(int amt) {
return "Rs." + amt * 45;
}
}
class Rupee extends Currency {
public Rupee(int amt) {
super("Rs.", amt);
}
}
class Dollar extends Currency {
public Dollar(int amt) {
super("$.", amt);
}
}
public class WriteWhit {
public static void main(String args[]) {
{
Random r = new Random();
try {
Currency currency;
FileOutputStream fos = new FileOutputStream("whit.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
System.out.println("Object Serialization - writting to whit.txt");
for (int i = 1; i < 25; i++) {
Object[] obj = {new Rupee(r.nextInt(5000)), new Dollar(r.nextInt(5000))};
currency = (Currency) obj[r.nextInt(2)];
System.out.println(currency);
oos.writeObject(currency);
oos.flush();
}
oos.close();
} catch (Exception e) {
System.out.println("Error..." + e);
}
}
}
}
SECOND PROG - READ PROGRAM
import java.io.*;
import java.util.*;
public class ReadDhana {
public static void main(String args[]) {
try {
Currency obj;
FileInputStream dha = new FileInputStream("whit.txt");
ObjectInputStream tam = new ObjectInputStream(dha);
obj = (Currency) tam.readObject();
System.out.println(obj + "="+ obj.dollarToRupee(obj.amount));
for (int i = 1; i <= 25; i++) {
obj = (Currency) tam.readObject();
if ((obj.currency).equals("$.")) {
System.out.println(obj + "="+ obj.dollarToRupee(obj.amount));
} else {
System.out.println(obj + "=" + obj);
}
}
tam.close();
} catch (Exception e) {
System.out.println("Program sucessfully executed!!");
}
}
}
Enjoy..!!