Encouragement and Support at the Click of a Button
Button clicked at 506115164645100 Frame: 1 Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO:Others do not get to claim ground on what you can and cannot do, Never Say Die!, Customer Experience and Quality can be Improved, Possible has yet to be defined, Past activation energy can be clear sailing, Never Say Die!, Past activation energy can be clear sailing, Nsdtp! Never Say Die Throughput!, Small changes do add up, You will Prevail!, Initial conditions can mean a lot, Past activation energy can be clear sailing, Don’t forget an extra bottle of water can change a lot, Possible has yet to be defined, Don’t forget an extra bottle of water can change a lot.
Don’t forget an extra bottle of water can change a lot, Never Say Die!, Possible is Power, Don’t forget an extra bottle of water can change a lot, You will Prevail!, Customer Experience and Quality can be Improved, Possible has yet to be defined, You will Prevail!, Possible is Power, Initial conditions can mean a lot, Customer Experience and Quality can be Improved, Past activation energy can be clear sailing, Don’t forget an extra bottle of water can change a lot, Possible is Power, You will Prevail!.
The future has yet to be written, You will Prevail!, Others do not get to claim ground on what you can and cannot do, Nsdtp! Never Say Die Throughput!, Possible has yet to be defined, Nsdtp! Never Say Die Throughput!, Nsdtp! Never Say Die Throughput!, Never Say Die!, The future has yet to be written, Never Say Die!, Encouragement Throughput has yet to be maximized, You can do it!, You will Prevail!, Nsdtp! Never Say Die Throughput!, The future has yet to be written.
Past activation energy can be clear sailing, Others do not get to claim ground on what you can and cannot do, Small changes do add up, Customer Experience and Quality can be Improved, Don’t forget an extra bottle of water can change a lot, Don’t forget an extra bottle of water can change a lot, Customer Experience and Quality can be Improved, You can do it!, Others do not get to claim ground on what you can and cannot do, Past activation energy can be clear sailing, Customer Experience and Quality can be Improved, Customer Experience and Quality can be Improved, You can do it!, Initial conditions can mean a lot, Customer Experience and Quality can be Improved.
Possible is Power, Nsdtp! Never Say Die Throughput!, You will Prevail!, You can do it!, Others do not get to claim ground on what you can and cannot do, Never Say Die!, You can do it!, Nsdtp! Never Say Die Throughput!, Customer Experience and Quality can be Improved, Never Say Die!, There is hope in a New Day, You can do it!, The future has yet to be written, There is hope in a New Day, The future has yet to be written.
Initial conditions can mean a lot, You will Prevail!, Customer Experience and Quality can be Improved, There is hope in a New Day, Others do not get to claim ground on what you can and cannot do, You can do it!, You will Prevail!, Never Say Die!, Small changes do add up, Don’t forget an extra bottle of water can change a lot, There is hope in a New Day, Don’t forget an extra bottle of water can change a lot, Possible is Power, Initial conditions can mean a lot, Encouragement Throughput has yet to be maximized.
Don’t forget an extra bottle of water can change a lot, There is hope in a New Day, Customer Experience and Quality can be Improved, Encouragement Throughput has yet to be maximized, Possible has yet to be defined, Possible is Power, Possible is Power, You will Prevail!, Possible is Power, You will Prevail!, Encouragement Throughput has yet to be maximized, Others do not get to claim ground on what you can and cannot do, Customer Experience and Quality can be Improved, Small changes do add up, The future has yet to be written.
Customer Experience and Quality can be Improved, Nsdtp! Never Say Die Throughput!, The future has yet to be written, There is hope in a New Day, Possible is Power, You will Prevail!, You can do it!, Possible is Power, Nsdtp! Never Say Die Throughput!, Possible has yet to be defined, Others do not get to claim ground on what you can and cannot do, Nsdtp! Never Say Die Throughput!, Possible has yet to be defined, Possible is Power, You can do it!.
You can do it!, Possible has yet to be defined, Past activation energy can be clear sailing, Customer Experience and Quality can be Improved, Encouragement Throughput has yet to be maximized, Past activation energy can be clear sailing, Small changes do add up, Customer Experience and Quality can be Improved, You will Prevail!, Others do not get to claim ground on what you can and cannot do, Possible has yet to be defined, There is hope in a New Day, You can do it!, There is hope in a New Day, Nsdtp! Never Say Die Throughput!.
The future has yet to be written, The future has yet to be written, You will Prevail!, Small changes do add up, Initial conditions can mean a lot, Encouragement Throughput has yet to be maximized, You will Prevail!, Possible has yet to be defined, You will Prevail!, Past activation energy can be clear sailing, Small changes do add up, You can do it!, Possible has yet to be defined, Possible is Power, You can do it!.
Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Water Desalination Plants, More Peacekeeping, Defensive Driving, More Peacemaking, Seat Belts, Improved Network Throughput and Reach, Water Well Drilling, Geneva Convention, Reduced Oppression, Improved Optics, Problem Solving, Teacher Training, Water Bottles, Water Desalination Plants, Problem Solving, Improved Telescopes, Cancer Research, More Peacemaking, Ethics, Habitat for Humanity, Habitat for Humanity, Ethics, Geneva Convention, Reduced Child Labor, Water Bottles Reduced Cognitive Biases Training, Respect, Improved Telescopes, Child Car Safety, Geneva Convention, Time Management, Improved Optics, Teacher Training, Reduced Cognitive Biases Training, Water Desalination Plants, Improved Optics, Ethics, Power Efficiency, More Peacekeeping, Improved Optics, Encouragement, Reduced Villain Level Contrast Training, Water Bottles, Improved English Support, Water Bottles, Rescue Blankets, Improved Network Throughput and Reach, Improved Architectural Blueprints, Motorcycle Helmets, Improved Medical Research Human Rights, Critical Thinking, Reduced Cognitive Biases Training, Focus, Seat Belts, Improved Telescopes, Improved Telescopes, Reduced Miscommunication, Improved Battery Power, Rescue Blankets, Linguistics Training, Reduced Child Labor, Linguistics Training, Human Rights, Reduced Child Labor, Improved Fire Codes, Rescue Blankets, Power Efficiency, Seat Belts, Respect, Improved Science Support, Improved Medical Tech, Improved Architectural Blueprints, Improved Microscopes, Improved Medical Tech Improved English Support, Improved Architectural Blueprints, Improved Optics, Improved Medical Research, Improved Learning, Reduced Child Labor, Defensive Driving, Clean Water Support, Improved Learning, Teacher Training, Validation, Electrical Safety, Improved Science Support, Improved Chemical Showers for Labs, Habitat for Humanity, Cancer Research, Seat Belts, More Peacekeeping, Focus, Reduced Miscommunication, Habitat for Humanity, Power Efficiency, Habitat for Humanity, Focus, Improved English Support Improved Science Support, Improved Telescopes, Improved Hospitals, More Peacemaking, Improved Math Support, Water Bottles, Rescue Blankets, Improved Optics, Reduced Oppression, Improved Science Support, Improved Hospitals, Improved Fire Codes, Encouragement, Power Efficiency, Seat Belts, Power Efficiency, Human Rights, Improved Science Support, Glass of Water, Water Desalination Plants, Teacher Training, More Peacemaking, More Peacekeeping, Improved Research Ethics, Improved Telescopes Encouragement, Habitat for Humanity, Improved Network Throughput and Reach, Reduced Child Labor, Reduced Cognitive Biases Training, Geneva Convention, More Peace building, Water Desalination Plants, Teacher Training, Criminal Defense Law, Motorcycle Helmets, Reduced Child Labor, More Peace, Improved Hospitals, Disaster Risk Reduction, Disaster Risk Reduction, More Peace building, More Peacemaking, Teacher Training, Improved Learning, More Peacemaking, Encouragement, Validation, Glass of Water, Improved Science Support Improved Microscopes, Criminal Defense Law, Time Management, Throughput, Improved Science Support, Problem Solving, Geneva Convention, Water Well Drilling, Improved Science Support, Reduced Oppression, Reduced Cognitive Biases Training, Defensive Driving, Improved Architectural Blueprints, Electrical Safety, Problem Solving, Water Bottles, More Peace, More Peace, Improved Chemical Showers for Labs, Respect, Cancer Research, Electrical Safety, Reduced Cognitive Biases Training, Improved Learning, Improved Learning Electrical Safety, Reduced Oppression, Focus, More Peacekeeping, Improved Learning, Problem Solving, Power Efficiency, Human Rights, Improved Science Support, More Peacemaking, Improved Optics, Power Efficiency, Improved Medical Research, Improved Fire Codes, Improved Architectural Blueprints, Improved Optics, Reduced Child Labor, Improved Chemical Showers for Labs, Reduced Child Labor, Human Rights, Critical Thinking, Improved Learning, Reduced Child Labor, Reduced Oppression, Reduced Villain Level Contrast Training Teacher Training, Improved Microscopes, Disaster Risk Reduction, Throughput, Improved Network Throughput and Reach, Reduced Child Labor, Criminal Defense Law, More Peace, Water Bottles, Power Efficiency, Defensive Driving, Problem Solving, Criminal Defense Law, Electrical Safety, Improved Math Support, Reduced Villain Level Contrast Training, Reduced Villain Level Contrast Training, Habitat for Humanity, Improved Fire Codes, Glass of Water, Respect, Diversity Training, More Peacemaking, Human Rights, Water Bottles Motorcycle Helmets, Improved English Support, Clean Water Support, Reduced Child Labor, Improved Architectural Blueprints, Glass of Water, Ethics, Time Management, Criminal Defense Law, Reduced Villain Level Contrast Training, Improved Architectural Blueprints, Improved Learning, Improved Medical Tech, Improved Optics, Rescue Blankets, Improved Architectural Blueprints, Criminal Defense Law, Improved Telescopes, Improved Network Throughput and Reach, Electrical Safety, Improved Architectural Blueprints, Cancer Research, Reduced Miscommunication, Water Well Drilling, Improved Microscopes Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Eat your vegetables, Clean your room, The prettiest flowers have the most leaves Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Clean your room, Do the dishes, Never Say Die! Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Eat your vegetables, Clean your room, you hug the lovable dictator Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Always be safe in the lab, Do the dishes, you hug the lovable dictator Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Go pick up some important documents from work, Always be safe in the lab, Never Say Die! Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Clean your room, Go pick up some important documents from work, Hug a kitten Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Clean your room, Eat your vegetables, you hug the lovable dictator Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Always be safe in the lab, Clean your room, Hug a kitten Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Eat your vegetables, Do the dishes, you hug the lovable dictator Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO: Eat your vegetables, Eat your vegetables, Hug a kitten Mar 13, 2023 5:02:46 AM controller.AddEncouragementLabelCommand generateSupport INFO:Hydroelectric Power, Momentum, Respect, Health Care, Drag, Defense Law, Hope, Availability, Chips, Public Relations, Equivocation, Proton, Shortest Path, Useful Work, Precedent, Normal, Equality, Irrational, Cover, Drought, False Dichotomy, Charming, Green Energy, Insulation, Macroeconomics
Shear Stregth, Point of View, Velocity, Weakest Link, Neutron, Logic, Scale, Forms – Aristotle, Creative Problem Solving, Measurement, Quantum Entanglement, Pattern Matching, Pain, Hydroelectric Power, High Pressure, Closed Loop Systems, Enthalpy, Experience, Creative Problem Solving, Orbits, Public Relations, Fuses, Projections, Ethics, Interpolation
Forms – Aristotle, Oranges, Acceleration, Useful Twists, Sea Shells, Fault Tolerance, Health, Frame of Reference, Don’t push against a brick wall, Measurement, Unknowns upsold to Knowns, Adequate Support, Disaster Risk Reduction, Proton, Flood Zone, Hydroelectric Power, Water, Enthalpy, Valence, Rounding, Ethics, Superposition, Charming, Teams, Respect
Practical Problem Solving, Bugs, Electron, Apples, Superposition, Speed of Light, Impossible, Acceleration, Corporate Image, Proton, Drilling Water Wells, Electron, Nitrogen, Imperfect System upsold to Perfect in Very Non Ideal Ways, Combustion, Apples, Blizzard, Comprehension, Flood, Exponential, Capitalism, Hydroelectric Power, Health, Theme, Interpolation
Symbolism, Precedent, Compression, Excited State, Force, High Pressure, Flood, Cantelope, Blizzard, Fuel, Atmosphere, Macroeconomics, BTUs, Practical Problem Solving, Proton, Speed of Sound, Disaster Risk Reduction, Strong Hypothesis, Induction, Nitrogen, Weak Hypothesis, Fire, Precision and Accuracy, Irrational, Time
Precedent, Excited State, Joules, Rate of Change, Theme, Expert, Obfuscation as Value Creation, Conductivity, Liquidity, Chain Thougts, Communicated Effectively, Directional Max Profit, Cover, Valence, Directed Power, Perception, Resistance, Irreversible Process, “I think therefore I am” – Rene Descarte, Point of View, Inadequate Support, Sales, Flood, Watts, Enthalpy
Appreciation, Logic, Joules, Sociology, Fries, Metaphors, Reasonable, Closed Loop Systems, Distrust, Flood Zone, Microeconomics, Useful Work, High Pressure, Precision and Accuracy, Water, Oxygen, Power Efficiency, Latency, Joules, Carbon, “To be is to be perceived” – David Hume, Customer Service, Pestilence, Variety, Sales
Statistical Anomaly, Atmosphere, Fuel, Fire, Speed of Light, “I think therefore I am” – Rene Descarte, Blizzard, Reaction Time, Illogical, Reducing Child Labor, Typhoon, Microeconomics, “To be is to be perceived” – David Hume, The Problem of Evil, Irreversible Process, Fair, Flood Zone, Precedent, Soda, Customer Service, Power Efficiency, Pineapples, Morally Right, Corporate Image, Greed
Rounding, Inequality, Fault Tolerance, Small Contributions Appreciated, Atmosphere, Enthalpy, Statistical Anomaly, Velocity, Coffee, Hypotheticals, Forms – Aristotle, Fuel, Cheesecake, Hurricane, Imagination, Forms – Aristotle, Theme, Orbits, Cheesecake, Truth as Relative, Hope, Irreversible Process, High Pressure, False Dichotomy, Useful Twists
Hypotheticals, Equality, Mangos, Resistance, Delayed Right Choice, Perception, Macroeconomics, Communicated Effectively, Projections, Cocunut, Carbon Monoxide, Don’t push against a brick wall, Fault Tolerance, Compressive Forces, Magnetism, Resistance, Microeconomics, Valence, Peaches, Inadequate Support, Carbon Monoxide, Communism, Justice, Red Herring, Fair
Mar 13, 2023 5:02:46 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes INFO: Performance Test, Adding Two One Digit Numbers 1 billion times Mar 13, 2023 5:02:46 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes INFO: — Processed 250,000,000 additions, current running time: 35917400 Mar 13, 2023 5:02:46 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes INFO: — Processed 500,000,000 additions, current running time: 92330400 Mar 13, 2023 5:02:46 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes INFO: — Processed 750,000,000 additions, current running time: 175530700 Mar 13, 2023 5:02:46 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes INFO: Test completed, recorded time in Nanoseconds: 277333200 Mar 13, 2023 5:02:46 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes_andCheckVerify_OneBillionTimes INFO: Performance Test, Adding Two One Digit Numbers 1 billion times Mar 13, 2023 5:02:46 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes_andCheckVerify_OneBillionTimes INFO: — Processed 250,000,000 additions, current running time: 238231600 Mar 13, 2023 5:02:46 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes_andCheckVerify_OneBillionTimes INFO: — Processed 500,000,000 additions, current running time: 486416800 Mar 13, 2023 5:02:47 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes_andCheckVerify_OneBillionTimes INFO: — Processed 750,000,000 additions, current running time: 751341200 Mar 13, 2023 5:02:47 AM performance.PerformanceTests addTwoOneDigitNumbers_OneBillionTimes_andCheckVerify_OneBillionTimes INFO: Test completed, recorded time in Nanoseconds: 1014200700Free Starter JavaFX Classes for Subtraction (MIT License)
package application;
import java.util.ArrayList;
import java.util.Random;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import performance.PerformanceUtil;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
public class SubtractionProblems extends Application {
private static Logger logger = Logger.getLogger(SubtractionProblems.class.toString());
private Random random = new Random(System.nanoTime());
private ArrayList<Integer> recordedTimes = new ArrayList<>();
private int value1=2;
private int value2=2;
public Canvas createCanvas() {
Canvas canvas = new Canvas(25,25);
canvasToColor(canvas,Color.RED);
canvas.setWidth(25);
canvas.setHeight(25);
return canvas;
}
public void canvasToColor(Canvas canvas, Color color) {
GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
graphicsContext.setFill(Paint.valueOf(color.toString()));
graphicsContext.fillRect(0, 0, 25, 25);
}
Label encouragementLabel = new Label("Never Say Die!");
Label problemSolvedInLabel = new Label("Problem Solved in: ms");
Label averageLabel = new Label("Average: ms");
Label answerCheckLabel = new Label("Test");
TextField answerField = new TextField();
Label problemLabel = new Label("");
Canvas canvas = createCanvas();
private void setupStage(Stage primaryStage) {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,500);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
VBox vbox = new VBox();
root.getChildren().add(vbox);
vbox.getChildren().add(canvas);
vbox.setMinHeight(400);
answerCheckLabel.setMinWidth(400);
answerCheckLabel.setMinHeight(200);
answerCheckLabel.setAlignment(Pos.CENTER);
vbox.getChildren().add(answerCheckLabel);
HBox hbox = new HBox();
vbox.getChildren().add(hbox);
hbox.setPadding(new Insets(10,10,10,10));
hbox.setMinWidth(400);
hbox.setMinHeight(200);
hbox.setAlignment(Pos.CENTER);
problemLabel.setText(value1+" - "+value2);
problemLabel.setFont(Font.font(20));
PerformanceUtil.getInstance().start();
hbox.getChildren().add(problemLabel);
Label equalsLabel = new Label(" = ");
hbox.getChildren().add(equalsLabel);
hbox.getChildren().add(answerField);
hbox.autosize();
vbox.getChildren().addAll(encouragementLabel,problemSolvedInLabel,averageLabel);
vbox.autosize();
answerField.setFont(Font.font(20));
}
private void handleKeyboardEvent(final KeyCode keyCode) {
if (keyCode==KeyCode.ENTER) {
System.out.println("Enter Key Released: "+answerField.getText());
try {
int value = Integer.parseInt(answerField.getText());
int difference = value1-value2;
if (value == difference) {
correctAnswer();
} else {
incorrectAnswer();
}
} catch (NumberFormatException e) {
System.out.println("Could not parse number");
}
}
}
private void correctAnswer() {
canvasToColor(canvas,Color.GREEN);
answerCheckLabel.setText("Answer is correct");
logger.info("Answer is correct");
PerformanceUtil.getInstance().stop();
logger.info("Problem solved in: "+PerformanceUtil.getInstance().getRecordedTime()+" ns");
logger.info("Problem solved in: "+PerformanceUtil.getInstance().getRecordedTimeMilliseconds()+" ms");
recordedTimes.add(PerformanceUtil.getInstance().getRecordedTimeMilliseconds());
problemSolvedInLabel.setText("Problem Solved in: "+PerformanceUtil.getInstance().getRecordedTimeMilliseconds()+" ms");
computeAverage();
answerField.setText("");
value1 = random.nextInt(0,10);
value2 = random.nextInt(0,10);
PerformanceUtil.getInstance().start();
problemLabel.setText(value1+" - "+value2);
}
private void incorrectAnswer() {
canvasToColor(canvas,Color.RED);
answerCheckLabel.setText("Answer is incorrect");
logger.info("Answer is incorrect");
logger.info("Problem solving running time: "+PerformanceUtil.getInstance().getRunningTime()+" ns");
}
@Override
public void start(Stage primaryStage) {
setupStage(primaryStage);
try {
answerField.setOnKeyReleased((event) -> {
KeyEvent keyEvent = (KeyEvent) event;
handleKeyboardEvent(keyEvent.getCode());
});
} catch(Exception e) {
e.printStackTrace();
}
}
public void computeAverage() {
int sum=0;
for (int i=0; i<recordedTimes.size(); i++) {
sum+=recordedTimes.get(i);
}
int average = sum/recordedTimes.size();
logger.info("Current Average: "+average+" ms");
averageLabel.setText("Average: "+average+" ms");
}
public static void main(String[] args) {
launch(args);
}
}
package performance;
import java.util.ArrayList;
public class PerformanceUtil {
private ArrayList<PerformanceReading> performanceReadings = new ArrayList<>();
private boolean stopWatchStarted = false;
private long startTime;
private long endTime;
private long recordedTime=0;
private static PerformanceUtil instance;
public static PerformanceUtil getInstance() {
if (null == instance) {
instance = new PerformanceUtil();
}
return instance;
}
public boolean start() {
if (stopWatchStarted) {
return false;
} else {
startTime=System.nanoTime();
stopWatchStarted=true;
return true;
}
}
public boolean stop() {
if (!stopWatchStarted) {
return false;
} else {
endTime=System.nanoTime();
stopWatchStarted=false;
return true;
}
}
public long getRunningTime() {
long runningTime = System.nanoTime()-startTime;
return runningTime;
}
public long getRecordedTime() {
recordedTime=endTime-startTime;
return recordedTime;
}
public int getRecordedTimeMilliseconds() {
recordedTime=endTime-startTime;
double milliseconds = recordedTime/1000000;
return (int) milliseconds;
}
public void clearPerformanceReadingsList() {
performanceReadings = new ArrayList<>();
}
public void addPerformanceReading(String performanceReadingName) {
long recordedTime = getRecordedTime();
PerformanceReading performanceReading = new PerformanceReading(recordedTime, performanceReadingName);
performanceReadings.add(performanceReading);
}
public PerformanceReading summarizePerformanceReadings(String readingName, ArrayList<PerformanceReading> readings) {
long sum=0;
for (int i=0; i<readings.size(); i++) {
sum = readings.get(i).getNanoseconds();
}
long average = sum/readings.size();
return new PerformanceReading(average, readingName);
}
public ArrayList<PerformanceReading> getPerformanceReadings() {
return performanceReadings;
}
}
package performance;
public class PerformanceReading {
public PerformanceReading(final long nanoseconds, final String name) {
this.nanoseconds = nanoseconds;
this.name = name;
}
private long nanoseconds;
private String name;
public long getNanoseconds() {
return nanoseconds;
}
public String getName() {
return name;
}
}
With a sequel for Division, also MIT License
package application;
import java.util.ArrayList;
import java.util.Random;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import performance.PerformanceUtil;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
public class DivisionProblems extends Application {
private static Logger logger = Logger.getLogger(DivisionProblems.class.toString());
private Random random = new Random(System.nanoTime());
private ArrayList<Integer> recordedTimes = new ArrayList<>();
private int value1=2;
private int value2=2;
public Canvas createCanvas() {
Canvas canvas = new Canvas(25,25);
canvasToColor(canvas,Color.RED);
canvas.setWidth(25);
canvas.setHeight(25);
return canvas;
}
public void canvasToColor(Canvas canvas, Color color) {
GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
graphicsContext.setFill(Paint.valueOf(color.toString()));
graphicsContext.fillRect(0, 0, 25, 25);
}
Label encouragementLabel = new Label("Never Say Die!");
Label problemSolvedInLabel = new Label("Problem Solved in: ms");
Label averageLabel = new Label("Average: ms");
Label answerCheckLabel = new Label("Test");
TextField answerField = new TextField();
Label problemLabel = new Label("");
Canvas canvas = createCanvas();
private void setupStage(Stage primaryStage) {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,500);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
VBox vbox = new VBox();
root.getChildren().add(vbox);
vbox.getChildren().add(canvas);
vbox.setMinHeight(400);
answerCheckLabel.setMinWidth(400);
answerCheckLabel.setMinHeight(200);
answerCheckLabel.setAlignment(Pos.CENTER);
vbox.getChildren().add(answerCheckLabel);
HBox hbox = new HBox();
vbox.getChildren().add(hbox);
hbox.setPadding(new Insets(10,10,10,10));
hbox.setMinWidth(400);
hbox.setMinHeight(200);
hbox.setAlignment(Pos.CENTER);
problemLabel.setText(value1+" / "+value2);
problemLabel.setFont(Font.font(20));
PerformanceUtil.getInstance().start();
hbox.getChildren().add(problemLabel);
Label equalsLabel = new Label(" = ");
hbox.getChildren().add(equalsLabel);
hbox.getChildren().add(answerField);
hbox.autosize();
vbox.getChildren().addAll(encouragementLabel,problemSolvedInLabel,averageLabel);
vbox.autosize();
answerField.setFont(Font.font(20));
}
private void handleKeyboardEvent(final KeyCode keyCode) {
if (keyCode==KeyCode.ENTER) {
System.out.println("Enter Key Released: "+answerField.getText());
try {
int value = Integer.parseInt(answerField.getText());
int quotient = value1/value2;
if (value == quotient) {
correctAnswer();
} else {
incorrectAnswer();
}
} catch (NumberFormatException e) {
System.out.println("Could not parse number");
}
}
}
private void correctAnswer() {
canvasToColor(canvas,Color.GREEN);
answerCheckLabel.setText("Answer is correct");
logger.info("Answer is correct");
PerformanceUtil.getInstance().stop();
logger.info("Problem solved in: "+PerformanceUtil.getInstance().getRecordedTime()+" ns");
logger.info("Problem solved in: "+PerformanceUtil.getInstance().getRecordedTimeMilliseconds()+" ms");
recordedTimes.add(PerformanceUtil.getInstance().getRecordedTimeMilliseconds());
problemSolvedInLabel.setText("Problem Solved in: "+PerformanceUtil.getInstance().getRecordedTimeMilliseconds()+" ms");
computeAverage();
answerField.setText("");
value1 = random.nextInt(0,10);
value2 = random.nextInt(1,10);
value1 = value1*value2;
PerformanceUtil.getInstance().start();
problemLabel.setText(value1+" / "+value2);
}
private void incorrectAnswer() {
canvasToColor(canvas,Color.RED);
answerCheckLabel.setText("Answer is incorrect");
logger.info("Answer is incorrect");
logger.info("Problem solving running time: "+PerformanceUtil.getInstance().getRunningTime()+" ns");
}
@Override
public void start(Stage primaryStage) {
setupStage(primaryStage);
try {
answerField.setOnKeyReleased((event) -> {
KeyEvent keyEvent = (KeyEvent) event;
handleKeyboardEvent(keyEvent.getCode());
});
} catch(Exception e) {
e.printStackTrace();
}
}
public void computeAverage() {
int sum=0;
for (int i=0; i<recordedTimes.size(); i++) {
sum+=recordedTimes.get(i);
}
int average = sum/recordedTimes.size();
logger.info("Current Average: "+average+" ms");
averageLabel.setText("Average: "+average+" ms");
}
public static void main(String[] args) {
launch(args);
}
}