001package strategy.ftoc;
002import java.io.BufferedReader;
003import java.io.InputStreamReader;
004import java.io.IOException;
005
006/* This example is from Robert C. Martin */
007public class Main {
008        public static void main(String[] args) {
009                (new App(new FtoC())).run();
010        }
011}
012final class App {
013        private AppStrategy s;
014        public App(AppStrategy s) {
015                this.s = s;
016        }
017        public void run() {
018                s.init();
019                while (!s.done())
020                        s.idle();
021                s.cleanup();
022        }
023}
024/* public */
025interface AppStrategy {
026        public void init();
027        public void idle();
028        public void cleanup();
029        public boolean done();
030}
031final class FtoC implements AppStrategy {
032        private boolean isDone = false;
033        private BufferedReader br;
034
035        public boolean done() {
036                return isDone;
037        }
038        public void init() {
039                br = new BufferedReader(new InputStreamReader(System.in));
040        }
041        public void idle() {
042                String fstring = readLine();
043                if (fstring == null || fstring.length() == 0) {
044                        isDone = true;
045                } else {
046                        double f = Double.parseDouble(fstring);
047                        double c = 5.0/9.0*(f-32);
048                        System.out.println("F=" + f + ", C=" + c);
049                }
050        }
051        public void cleanup() {
052                System.out.println("FtoC exit");
053        }
054        private String readLine() {
055                try { return br.readLine(); }
056                catch(IOException e) { return null; }
057        }
058}