|
| United States Worldwide |
|
package opjtutorial.ccalc;
import java.io.*; import java.util.*; import org.opj.*; public class Main { static { OPRuntime.roots.add(Main.class); } private static Main self = new Main(); private static List history = new LinkedList(); private float exchangeRate; public static void main(String args[]) { try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.print("Input a command: "); int command = in.read(); String arg = in.readLine(); switch (command) { case 'x': history.add(0, new Float(self.exchangeRate)); exchangeRate = Float.parseFloat(arg); System.out.println("Exchange rate set to " + self.exchangeRate); break; case 'c': { float amount = Float.parseFloat(arg); System.out.println("Amount " + amount + " converts to " + amount*self.exchangeRate); } break; case 'h': { System.out.print("Exchange rate history: " + self.exchangeRate); ListIterator iter = history.listIterator(); while (iter.hasNext()) { System.out.print(" " + ((Float)(iter.next())).floatValue()); } System.out.println(""); } break; case 'q': System.exit(0); break; default: System.out.println("Unknown command " + command); } OPRuntime.checkpoint(); } } catch (Exception e) { System.out.println(e); System.exit(-1); } } | ||||||||||||||||||||||