Advertisement
HasteBin0

Java Basic LUI

Jul 13th, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 32.03 KB | None | 0 0
  1. package main;
  2.  
  3. import static java.lang.System.out;
  4. import static java.lang.System.err;
  5. import static java.lang.System.in;
  6.  
  7. import java.util.Scanner;
  8.  
  9. enum FirstSecondValue {
  10.     first(0),
  11.     second(1);
  12.  
  13.     private final int witch;
  14.  
  15.     private FirstSecondValue(int witch) {
  16.         this.witch = witch;
  17.     }
  18.  
  19.     public int getWitch() {
  20.         return witch;
  21.     }
  22. }
  23.  
  24. /**
  25.  * Toy with the Fibonacci sequence. Find out about the Golden Ratio.
  26.  * https://youtu.be/6nSfJEDZ_WM
  27.  *
  28.  * @author Aidan
  29.  */
  30. final class FibonacciToy {
  31.  
  32.     static {
  33.         GOLDEN_RATIO = (Math.sqrt(5) + 1d) / 2d;
  34.     }
  35.  
  36.     private static final Double GOLDEN_RATIO;
  37.  
  38.     private final Integer numbers[]; // Previous, Current
  39.  
  40.     public FibonacciToy() {
  41.         this.numbers = new Integer[]{1, 1};
  42.     }
  43.  
  44.     public static Double getGoldenRatio() {
  45.         return GOLDEN_RATIO;
  46.     }
  47.  
  48.     public Double approximateGoldenRatio() {
  49.         return (Double) ((double) (int) this.numbers[1] / (double) (int) this.numbers[0]);
  50.     }
  51.  
  52.     public Integer get(FirstSecondValue fs) {
  53.         return this.numbers[fs.getWitch()];
  54.     }
  55.  
  56.     public void set(Integer value, FirstSecondValue fs) {
  57.         this.numbers[fs.getWitch()] = value;
  58.     }
  59.  
  60.     public void stepBackOnce() {
  61.         final Integer tmp[] = new Integer[]{
  62.             this.numbers[1] - this.numbers[0],
  63.             this.numbers[0]
  64.         };
  65.         this.numbers[0] = tmp[0];
  66.         this.numbers[1] = tmp[1];
  67.     }
  68.  
  69.     public void stepForwardOnce() {
  70.         final Integer tmp[] = new Integer[]{
  71.             this.numbers[1],
  72.             this.numbers[0] + this.numbers[1]
  73.         };
  74.         this.numbers[0] = tmp[0];
  75.         this.numbers[1] = tmp[1];
  76.     }
  77.  
  78.     public void stepForward(Integer steps) {
  79.         for (Integer i = 0; i < steps; i++) {
  80.             this.stepForwardOnce();
  81.         }
  82.     }
  83.  
  84.     public void stepBackward(Integer steps) {
  85.         for (Integer i = 0; i < steps; i++) {
  86.             this.stepBackOnce();
  87.         }
  88.     }
  89.  
  90.     public void stepForwardAndRun(Runnable r, Integer steps) {
  91.         for (Integer i = 0; i < steps; i++) {
  92.             this.stepForwardOnce();
  93.             r.run();
  94.         }
  95.     }
  96.  
  97.     public void stepBackwardAndRun(Runnable r, Integer steps) {
  98.         for (Integer i = 0; i < steps; i++) {
  99.             this.stepBackOnce();
  100.             r.run();
  101.         }
  102.     }
  103.  
  104. }
  105.  
  106. /**
  107.  * Interact with a Fibonacci Sequence to find its Pisano Period.
  108.  * https://youtu.be/Nu-lW-Ifyec
  109.  *
  110.  * @author Aidan
  111.  */
  112. final class PisanoPeriod {
  113.  
  114.     private final FibonacciToy toy;
  115.     private Integer modulo, periodicity;
  116.  
  117.     public PisanoPeriod(FibonacciToy toy) {
  118.         this.toy = toy;
  119.         this.modulo = 2;
  120.         this.periodicity = 0;
  121.     }
  122.  
  123.     public Integer getModulo() {
  124.         return this.modulo;
  125.     }
  126.  
  127.     public Integer getPeriodicy() {
  128.         return this.periodicity;
  129.     }
  130.  
  131.     public void setModulo(Integer modulo) {
  132.         this.modulo = modulo;
  133.     }
  134.  
  135.     // Pisano Period
  136.     public void findPeriodicity() {
  137.         final Integer save[] = new Integer[2];
  138.         save[0] = this.toy.get(FirstSecondValue.first);
  139.         save[1] = this.toy.get(FirstSecondValue.second);
  140.         //
  141.         Integer tmp[] = new Integer[2];
  142.         Boolean hit01 = false;
  143.         Integer period = 0;
  144.         //
  145.         while (true) {
  146.             this.toy.stepForwardOnce();
  147.             tmp[0] = this.toy.get(FirstSecondValue.first) % modulo;
  148.             tmp[1] = this.toy.get(FirstSecondValue.second) % modulo;
  149.             //
  150.             if (tmp[0] == 0 && tmp[1] == 1) {
  151.                 if (hit01) {
  152.                     break;
  153.                 } else {
  154.                     hit01 = true;
  155.                 }
  156.             }
  157.             //
  158.             if (hit01) {
  159.                 period += 1;
  160.             }
  161.         }
  162.         this.toy.set(save[0], FirstSecondValue.first);
  163.         this.toy.set(save[1], FirstSecondValue.second);
  164.         //
  165.         this.periodicity = period;
  166.     }
  167. }
  168.  
  169. /**
  170.  * Access a thread-safe boolean.
  171.  *
  172.  * @author Aidan
  173.  */
  174. final class LockedBoolean {
  175.  
  176.     private volatile Boolean x;
  177.     private final Object l;
  178.  
  179.     public LockedBoolean(Boolean i) {
  180.         this.l = new Object();
  181.         this.setX(i);
  182.     }
  183.  
  184.     public Boolean getX() {
  185.         synchronized (this.l) {
  186.             return this.x;
  187.         }
  188.     }
  189.  
  190.     public void setX(Boolean x) {
  191.         synchronized (this.l) {
  192.             this.x = x;
  193.         }
  194.     }
  195.  
  196.     public void flip() {
  197.         this.setX(!this.getX());
  198.     }
  199. }
  200.  
  201. /**
  202.  * Represent a user's place in the LUI.
  203.  *
  204.  * @author Aidan
  205.  */
  206. enum Pages {
  207.     MAIN,
  208.     ALLOCATE,
  209.     DEALLOCATE,
  210.     MANIPUATE,
  211.     M_GS_FIRST_NUMBER,
  212.     M_GS_SECOND_NUMBER,
  213.     M_STEP_FORWARD_ONCE,
  214.     M_STEP_BACKWARD_ONCE,
  215.     M_STEP_FORWARD,
  216.     M_STEP_BACKWARD,
  217.     M_FIND_PISANO_PERIOD,
  218.     M_FIND_PISANO_PERIOD_GET_MOD,
  219.     M_FIND_PISANO_PERIOD_SET_MOD,
  220.     M_FIND_PISANO_PERIOD_FIND,
  221.     M_FIND_PISANO_PERIOD_DISPLAY,
  222.     M_FIND_PISANO_PERIOD_EXIT,
  223.     M_GA_GOLDEN_RATIO,
  224.     M_GA_GOLDEN_RATIO_APPROX,
  225.     M_GA_GOLDEN_RATIO_EXACT,
  226.     M_GA_GOLDEN_RATIO_DEGREE,
  227.     M_GA_EXIT,
  228.     M_EXIT,
  229.     EXIT
  230. }
  231.  
  232. /**
  233.  * Demonstrate a well-structured LUI. https://youtu.be/SGZr06TpORE
  234.  *
  235.  * @author Aidan
  236.  */
  237. public class ConsolePages {
  238.  
  239.     private static Boolean getTF(final String pmt, final String o1, final String o2) {
  240.         final String tmp_pmt = "For " + pmt + ", " + o1 + " [0] or " + o2 + " [1]? ";
  241.         Short input;
  242.         while (true) {
  243.             out.print(tmp_pmt);
  244.             out.flush();
  245.             try {
  246.                 input = new Scanner(in).nextShort();
  247.                 if (input == 0) {
  248.                     return true;
  249.                 }
  250.                 if (input == 1) {
  251.                     return false;
  252.                 }
  253.             } catch (Exception e) {
  254.             }
  255.         }
  256.     }
  257.  
  258.     private static Boolean getTF(final String pmt, final String o1, final String o2, final String o3) {
  259.         final String tmp_pmt = "For " + pmt + ", " + o1 + " [0], " + o2 + " [1], " + o3 + " [2]? ";
  260.         Short input;
  261.         while (true) {
  262.             out.print(tmp_pmt);
  263.             out.flush();
  264.             try {
  265.                 input = new Scanner(in).nextShort();
  266.                 if (input == 0) {
  267.                     return null;
  268.                 }
  269.                 if (input == 1) {
  270.                     return false;
  271.                 }
  272.                 if (input == 2) {
  273.                     return true;
  274.                 }
  275.             } catch (Exception e) {
  276.             }
  277.         }
  278.     }
  279.  
  280.     private static Integer getInt(String pmt) {
  281.         final String tmp_pmt = pmt + ": ";
  282.         Integer input;
  283.         while (true) {
  284.             out.print(tmp_pmt);
  285.             out.flush();
  286.             try {
  287.                 input = new Scanner(in).nextInt();
  288.                 if (input > 0) {
  289.                     return input;
  290.                 }
  291.             } catch (Exception e) {
  292.             }
  293.         }
  294.     }
  295.  
  296.     public static void main(String[] args) {
  297.         FibonacciToy toy = null;
  298.         Pages page = Pages.ALLOCATE;
  299.  
  300.         MainLoop:
  301.         while (true) {
  302.             switch (page) {
  303.                 case MAIN: {
  304.                     out.println(
  305.                             "\nMain Page:\n"
  306.                             + "1. Allocate Toy\n"
  307.                             + "2. Deallocate Toy\n"
  308.                             + "3. Manipulate Toy\n"
  309.                             + "4. Exit Program");
  310.                     out.flush();
  311.                     ManipulationLoop:
  312.                     while (true) {
  313.                         out.print("Option: ");
  314.                         out.flush();
  315.                         try {
  316.                             switch (new Scanner(in).nextShort()) {
  317.                                 case 1: {
  318.                                     page = Pages.ALLOCATE;
  319.                                     break ManipulationLoop;
  320.                                 }
  321.                                 case 2: {
  322.                                     page = Pages.DEALLOCATE;
  323.                                     break ManipulationLoop;
  324.                                 }
  325.                                 case 3: {
  326.                                     page = Pages.MANIPUATE;
  327.                                     break ManipulationLoop;
  328.                                 }
  329.                                 case 4: {
  330.                                     page = Pages.EXIT;
  331.                                     break ManipulationLoop;
  332.                                 }
  333.                             }
  334.                         } catch (Exception e) {
  335.                         }
  336.                     }
  337.                     break;
  338.                 }
  339.                 case ALLOCATE: {
  340.                     if (toy == null) {
  341.                         try {
  342.                             toy = new FibonacciToy();
  343.                             out.println("Toy allocation succeeded.");
  344.                             out.flush();
  345.                         } catch (Exception e) {
  346.                             err.println("Toy allocation failed: Memory is out.");
  347.                             err.flush();
  348.                         }
  349.                     } else {
  350.                         err.println("Toy is already allocated.");
  351.                         err.flush();
  352.                     }
  353.                     page = Pages.MAIN;
  354.                     break;
  355.                 }
  356.                 case DEALLOCATE: {
  357.                     if (toy != null) {
  358.                         toy = null;
  359.                         out.println("Toy deallocation succeeded.");
  360.                         out.flush();
  361.                     } else {
  362.                         err.println("Toy not yet allocated.");
  363.                         out.flush();
  364.                     }
  365.                     page = Pages.MAIN;
  366.                     break;
  367.                 }
  368.                 case MANIPUATE: {
  369.                     if (toy != null) {
  370.                         ManipulationMainLoop:
  371.                         while (true) {
  372.                             switch (page) {
  373.                                 case MANIPUATE: {
  374.                                     out.println(
  375.                                             "\nManipulation Page:\n"
  376.                                             + "1. Set/get First  Fibonacci Number\n"
  377.                                             + "2. Set/get Second Fibonacci Number\n"
  378.                                             + "3. Step Forward/backward Once\n"
  379.                                             + "4. Step Forward/backward Multiple Times\n"
  380.                                             + "5. Find period Of Fibonacci Sequence\n"
  381.                                             + "6. Get/approximate the Golden Ratio\n"
  382.                                             + "7. Return to Main Page");
  383.                                     out.flush();
  384.                                     ManipulationSubMainLoop:
  385.                                     while (true) {
  386.                                         out.print("Option: ");
  387.                                         out.flush();
  388.                                         try {
  389.                                             switch (new Scanner(in).nextShort()) {
  390.                                                 case 1: {
  391.                                                     page = Pages.M_GS_FIRST_NUMBER;
  392.                                                     break ManipulationSubMainLoop;
  393.                                                 }
  394.                                                 case 2: {
  395.                                                     page = Pages.M_GS_SECOND_NUMBER;
  396.                                                     break ManipulationSubMainLoop;
  397.                                                 }
  398.                                                 case 3: {
  399.                                                     page = Pages.M_STEP_BACKWARD_ONCE;
  400.                                                     break ManipulationSubMainLoop;
  401.                                                 }
  402.                                                 case 4: {
  403.                                                     page = Pages.M_STEP_BACKWARD;
  404.                                                     break ManipulationSubMainLoop;
  405.                                                 }
  406.                                                 case 5: {
  407.                                                     page = Pages.M_FIND_PISANO_PERIOD;
  408.                                                     break ManipulationSubMainLoop;
  409.                                                 }
  410.                                                 case 6: {
  411.                                                     page = Pages.M_GA_GOLDEN_RATIO;
  412.                                                     break ManipulationSubMainLoop;
  413.                                                 }
  414.                                                 case 7: {
  415.                                                     page = Pages.M_EXIT;
  416.                                                     break ManipulationSubMainLoop;
  417.                                                 }
  418.                                             }
  419.                                         } catch (Exception e) {
  420.                                         }
  421.                                     }
  422.                                     break;
  423.                                 }
  424.                                 case M_GS_FIRST_NUMBER: {
  425.                                     final Boolean gs = getTF("the first number", "set", "get");
  426.                                     if (gs) {
  427.                                         Integer input;
  428.                                         while (true) {
  429.                                             out.print("New value: ");
  430.                                             out.flush();
  431.                                             try {
  432.                                                 input = new Scanner(in).nextInt();
  433.                                                 break;
  434.                                             } catch (Exception e) {
  435.                                             }
  436.                                         }
  437.                                         if (input <= toy.get(FirstSecondValue.second)) {
  438.                                             toy.set(input, FirstSecondValue.first);
  439.                                             out.println("Succeeded.");
  440.                                             out.flush();
  441.                                         } else {
  442.                                             err.println("The number " + input + " is greater than " + toy.get(FirstSecondValue.second) + '.');
  443.                                             err.flush();
  444.                                         }
  445.                                     } else {
  446.                                         out.println("The first number is " + toy.get(FirstSecondValue.first) + '.');
  447.                                         out.flush();
  448.                                     }
  449.                                     page = Pages.MANIPUATE;
  450.                                     break;
  451.                                 }
  452.                                 case M_GS_SECOND_NUMBER: {
  453.                                     final Boolean gs = getTF("the second number", "set", "get");
  454.                                     if (gs) {
  455.                                         Integer input;
  456.                                         while (true) {
  457.                                             out.print("New value: ");
  458.                                             out.flush();
  459.                                             try {
  460.                                                 input = new Scanner(in).nextInt();
  461.                                                 break;
  462.                                             } catch (Exception e) {
  463.                                             }
  464.                                         }
  465.                                         if (input >= toy.get(FirstSecondValue.first)) {
  466.                                             toy.set(input, FirstSecondValue.second);
  467.                                             out.println("Succeeded.");
  468.                                             out.flush();
  469.                                         } else {
  470.                                             err.println("The number " + input + " is less than " + toy.get(FirstSecondValue.first) + '.');
  471.                                             err.flush();
  472.                                         }
  473.                                     } else {
  474.                                         out.println("The second number is " + toy.get(FirstSecondValue.second) + '.');
  475.                                         out.flush();
  476.                                     }
  477.                                     page = Pages.MANIPUATE;
  478.                                     break;
  479.                                 }
  480.                                 case M_STEP_BACKWARD_ONCE: {
  481.                                     final Boolean direction = getTF("one step, go", "backward", "forward");
  482.                                     if (direction) {
  483.                                         toy.stepBackOnce();
  484.                                         out.println("Succeeded.");
  485.                                         out.flush();
  486.                                         page = Pages.MANIPUATE;
  487.                                     } else {
  488.                                         page = Pages.M_STEP_FORWARD_ONCE;
  489.                                     }
  490.                                     break;
  491.                                 }
  492.                                 case M_STEP_BACKWARD: {
  493.                                     final Boolean direction = getTF("some steps, go", "backward", "forward");
  494.                                     if (direction) {
  495.                                         toy.stepBackward(getInt("Number of steps backward"));
  496.                                         out.println("Succeeded.");
  497.                                         out.flush();
  498.                                         page = Pages.MANIPUATE;
  499.                                     } else {
  500.                                         page = Pages.M_STEP_FORWARD;
  501.                                     }
  502.                                     break;
  503.                                 }
  504.                                 case M_STEP_FORWARD_ONCE: {
  505.                                     toy.stepForwardOnce();
  506.                                     out.println("Succeeded.");
  507.                                     out.flush();
  508.                                     page = Pages.MANIPUATE;
  509.                                     break;
  510.                                 }
  511.                                 case M_STEP_FORWARD: {
  512.                                     toy.stepForward(getInt("Number of steps forward"));
  513.                                     out.println("Succeeded.");
  514.                                     out.flush();
  515.                                     page = Pages.MANIPUATE;
  516.                                     break;
  517.                                 }
  518.                                 case M_FIND_PISANO_PERIOD: {
  519.                                     final PisanoPeriod period = new PisanoPeriod(toy);
  520.                                     PisanoLoop:
  521.                                     while (true) {
  522.                                         switch (page) {
  523.                                             case M_FIND_PISANO_PERIOD: {
  524.                                                 out.println(
  525.                                                         "\nPisano Period:\n"
  526.                                                         + "1. Get the modulus\n"
  527.                                                         + "2. Set the modulus\n"
  528.                                                         + "3. Find the period\n"
  529.                                                         + "4. Show the period\n"
  530.                                                         + "5. Return to the manipulation page"
  531.                                                 );
  532.                                                 out.flush();
  533.                                                 PisanoOptionLoop:
  534.                                                 while (true) {
  535.                                                     out.print("Option: ");
  536.                                                     out.flush();
  537.                                                     switch (new Scanner(in).nextShort()) {
  538.                                                         case 1: {
  539.                                                             page = Pages.M_FIND_PISANO_PERIOD_GET_MOD;
  540.                                                             break PisanoOptionLoop;
  541.                                                         }
  542.                                                         case 2: {
  543.                                                             page = Pages.M_FIND_PISANO_PERIOD_SET_MOD;
  544.                                                             break PisanoOptionLoop;
  545.                                                         }
  546.                                                         case 3: {
  547.                                                             page = Pages.M_FIND_PISANO_PERIOD_FIND;
  548.                                                             break PisanoOptionLoop;
  549.                                                         }
  550.                                                         case 4: {
  551.                                                             page = Pages.M_FIND_PISANO_PERIOD_DISPLAY;
  552.                                                             break PisanoOptionLoop;
  553.                                                         }
  554.                                                         case 5: {
  555.                                                             page = Pages.M_FIND_PISANO_PERIOD_EXIT;
  556.                                                             break PisanoOptionLoop;
  557.                                                         }
  558.                                                     }
  559.                                                 }
  560.                                                 break;
  561.                                             }
  562.                                             case M_FIND_PISANO_PERIOD_GET_MOD: {
  563.                                                 out.println("The modulus is " + period.getModulo() + '.');
  564.                                                 out.flush();
  565.                                                 page = Pages.M_FIND_PISANO_PERIOD;
  566.                                                 break;
  567.                                             }
  568.                                             case M_FIND_PISANO_PERIOD_SET_MOD: {
  569.                                                 while (true) {
  570.                                                     final Integer input = getInt("Set modulus to (2+)");
  571.                                                     if (input != 1) {
  572.                                                         period.setModulo(input);
  573.                                                         break;
  574.                                                     }
  575.                                                 }
  576.                                                 page = Pages.M_FIND_PISANO_PERIOD;
  577.                                                 break;
  578.                                             }
  579.                                             case M_FIND_PISANO_PERIOD_FIND: {
  580.                                                 LockedBoolean event = new LockedBoolean(Boolean.TRUE);
  581.                                                 Thread runner = new Thread(() -> {
  582.                                                     final char display[] = new char[]{'|', '\\', '-', '/'};
  583.                                                     Integer location = 0;
  584.                                                     while (event.getX()) {
  585.                                                         out.print("\r" + display[location]);
  586.                                                         out.flush();
  587.                                                         if (++location == 5) {
  588.                                                             location = 0;
  589.                                                         }
  590.                                                         try {
  591.                                                             Thread.sleep(1000L);
  592.                                                         } catch (InterruptedException ex) {
  593.                                                         }
  594.                                                     }
  595.                                                     out.println("\r \rDone.");
  596.                                                     out.flush();
  597.                                                 });
  598.                                                 runner.setDaemon(true);
  599.                                                 runner.setName("PROGRES");
  600.                                                 runner.start();
  601.                                                 period.findPeriodicity();
  602.                                                 event.flip();
  603.                                                 while (true) {
  604.                                                     try {
  605.                                                         runner.join();
  606.                                                         break;
  607.                                                     } catch (InterruptedException e) {
  608.                                                     }
  609.                                                 }
  610.                                                 page = Pages.M_FIND_PISANO_PERIOD;
  611.                                                 break;
  612.                                             }
  613.                                             case M_FIND_PISANO_PERIOD_DISPLAY: {
  614.                                                 out.println("For the modulus of " + period.getModulo() + ", the Pisano period is " + period.getPeriodicy() + '.');
  615.                                                 out.flush();
  616.                                                 page = Pages.M_FIND_PISANO_PERIOD;
  617.                                                 break;
  618.                                             }
  619.                                             case M_FIND_PISANO_PERIOD_EXIT: {
  620.                                                 break PisanoLoop;
  621.                                             }
  622.                                         }
  623.                                     }
  624.                                     page = Pages.MANIPUATE;
  625.                                     break;
  626.                                 }
  627.                                 case M_GA_GOLDEN_RATIO: {
  628.                                     GoldenRatioMainLoop:
  629.                                     while (true) {
  630.                                         switch (page) {
  631.                                             case M_GA_GOLDEN_RATIO: {
  632.                                                 out.println(
  633.                                                         "\nGolden Ratio:\n"
  634.                                                         + "1. Approximate\n"
  635.                                                         + "2. Get it exactly\n"
  636.                                                         + "3. Compare the two\n"
  637.                                                         + "4. Return to the manipulation page"
  638.                                                 );
  639.                                                 out.flush();
  640.                                                 GoldenRatioOptionLoop:
  641.                                                 while (true) {
  642.                                                     out.print("Option: ");
  643.                                                     out.flush();
  644.                                                     try {
  645.                                                         switch (new Scanner(in).nextShort()) {
  646.                                                             case 1: {
  647.                                                                 page = Pages.M_GA_GOLDEN_RATIO_APPROX;
  648.                                                                 break GoldenRatioOptionLoop;
  649.                                                             }
  650.                                                             case 2: {
  651.                                                                 page = Pages.M_GA_GOLDEN_RATIO_EXACT;
  652.                                                                 break GoldenRatioOptionLoop;
  653.                                                             }
  654.                                                             case 3: {
  655.                                                                 page = Pages.M_GA_GOLDEN_RATIO_DEGREE;
  656.                                                                 break GoldenRatioOptionLoop;
  657.                                                             }
  658.                                                             case 4: {
  659.                                                                 page = Pages.M_GA_EXIT;
  660.                                                                 break GoldenRatioOptionLoop;
  661.                                                             }
  662.                                                         }
  663.                                                     } catch (Exception e) {
  664.                                                     }
  665.                                                 }
  666.                                                 break;
  667.                                             }
  668.                                             case M_GA_GOLDEN_RATIO_APPROX: {
  669.                                                 out.println("The approximation is currently " + toy.approximateGoldenRatio() + '.');
  670.                                                 out.flush();
  671.                                                 page = Pages.M_GA_GOLDEN_RATIO;
  672.                                                 break;
  673.                                             }
  674.                                             case M_GA_GOLDEN_RATIO_EXACT: {
  675.                                                 out.println("The Golden Ratio \u03C6 is exectly " + FibonacciToy.getGoldenRatio() + '.');
  676.                                                 out.flush();
  677.                                                 page = Pages.M_GA_GOLDEN_RATIO;
  678.                                                 break;
  679.                                             }
  680.                                             case M_GA_GOLDEN_RATIO_DEGREE: {
  681.                                                 final Integer percentage = (int) (toy.approximateGoldenRatio() / FibonacciToy.getGoldenRatio() * 100);
  682.                                                 out.println("The current approximation is " + percentage + "% accurate.");
  683.                                                 out.flush();
  684.                                                 page = Pages.M_GA_GOLDEN_RATIO;
  685.                                                 break;
  686.                                             }
  687.                                             case M_GA_EXIT: {
  688.                                                 break GoldenRatioMainLoop;
  689.                                             }
  690.                                         }
  691.                                     }
  692.                                     page = Pages.MANIPUATE;
  693.                                     break;
  694.                                 }
  695.                                 case M_EXIT: {
  696.                                     break ManipulationMainLoop;
  697.                                 }
  698.                             }
  699.                         }
  700.                     } else {
  701.                         err.println("No toy present.");
  702.                         err.flush();
  703.                     }
  704.                     page = Pages.MAIN;
  705.                     break;
  706.                 }
  707.                 case EXIT: {
  708.                     break MainLoop;
  709.                 }
  710.             }
  711.         }
  712.     }
  713.  
  714. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement