Untitled
unknown
plain_text
a year ago
2.6 kB
3
Indexable
Never
Bill.java: public class Bill extends Money{ private int dollars; public Bill (int d) { dollars = d; } public int getValue () { return dollars; } public String toString(){ return ("$ "+dollars+".00"); } } Coin.java: public abstract class Coin extends Money { private int value; public Coin(int v) { value = v; } public int getValue () { return value; } public String toString() { String a=""; if(value<10) a="0"; return ("$ 0."+a+getValue()); } } Dime.java: public class Dime extends Coin{ public Dime () { super (10); } } Money.java: import java.io.*; public class Money implements Serializable { } Nikels.java: public class Nikels extends Coin{ public Nikels () { super (5); } } Penny.java: public class Penny extends Coin{ public Penny(){ super(1); } } Quarter.java: public class Quarter extends Coin { public Quarter () { super (25); } } ReadDate.java: import java.io.*; import java.util.Date; public class ReadDate { public static void main(String argv[]) throws Exception { FileInputStream fis = new FileInputStream("date.out"); ObjectInputStream ois = new ObjectInputStream(fis); Date date = (Date) ois.readObject(); System.out.println("The date is: "+date); ois.close(); fis.close(); } } ReadMoney.java: import java.io.*; import java.util.Date; public class ReadMoney { public static void main(String argv[]) throws Exception { FileInputStream fis = new FileInputStream("date.out"); ObjectInputStream ois = new ObjectInputStream(fis); while(fis.available()!=0){ Object a=ois.readObject(); if(a instanceof Quarter)System.out.println((Quarter)a); else if(a instanceof Nikels)System.out.println((Nikels)a); else if(a instanceof Dime)System.out.println((Dime)a); else if(a instanceof Penny)System.out.println((Penny)a); } ois.close(); fis.close(); } } SaveDate.java: import java.io.*; import java.util.Date; public class SaveDate { public static void main(String argv[]) throws Exception { FileOutputStream fos = new FileOutputStream("date.out"); ObjectOutputStream oos = new ObjectOutputStream(fos); Date date = new Date(); oos.writeObject(date); oos.flush(); oos.close(); fos.close(); } } SaveMoney.java: import java.io.*; import java.util.Date; public class SaveMoney { public static void main(String argv[]) throws Exception { FileOutputStream fos = new FileOutputStream("date.out"); ObjectOutputStream oos = new ObjectOutputStream(fos); for(int i=0;i<2;i++){ Quarter q = new Quarter(); oos.writeObject(q); Nikels n = new Nikels(); oos.writeObject(n); Dime d = new Dime(); oos.writeObject(d); Penny p = new Penny(); oos.writeObject(p); } oos.flush(); oos.close(); fos.close(); } }