Question
16.5 Covert Number I successfully wrote code for the scenario below. I would like someone from yourteam to rewrite the code using a different approach.
16.5 Covert Number
I successfully wrote code for the scenario below. I would like someone from yourteam to rewrite the code using a different approach. This will allow me to see how someone else may go about coding this program and ultimately coming out with the same results. Please code using Java and verify it will run in a Java IDE. My code can be found below. Thanks.
(Convert numbers) Write a program that converts between decimal, hex, and binarynumbers, as shown in the Figure below. When you enter a decimal value in the decimal value text field and press the Enter key, its corresponding hex and binary numbers aredisplayed in the other two text fields. Likewise, you can enter values in the other fieldsand convert them accordingly. (Hint: Use the Integer.parseInt(s, radix)method to parse a string to a decimal and use Integer.toHexString(decimal) and Integer.toBinaryString(decimal) to obtain a hex number or a binarynumber from a decimal.)
This is my code for the program. It runs successfully, no issues. Please re-code using a different approach so I can compare and contrast a different ways to write the same program.
import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class Exercise_05 extends Application { @Override public void start(Stage primaryStage) throws Exception { DecHexBinaryPane pane = new DecHexBinaryPane(); primaryStage.setTitle("Decimal - Hex - Binary Calculator"); primaryStage.setScene(new Scene(pane)); primaryStage.show(); } private class DecHexBinaryPane extends GridPane { Label lblDecimal = new Label("Decimal:"); Label lblHex = new Label("Hex:"); Label lblBinary = new Label("Binary:"); TextField tfDecimal = new TextField(); TextField tfHex = new TextField(); TextField tfBinary = new TextField(); Integer integer = 0; private DecHexBinaryPane() { setHgap(10); setVgap(10); setPadding(new Insets(10, 10, 10, 10)); TextField[] textFields = new TextField[3]; // row 0 add(lblDecimal, 0, 0); add(tfDecimal, 1, 0); textFields[0] = tfDecimal; // row 1 add(lblHex, 0, 1); add(tfHex, 1, 1); textFields[1] = tfHex; // row 2 add(lblBinary, 0, 2); add(tfBinary, 1, 2); textFields[2] = tfBinary; for (int i = 0; i { integer = new Integer(tfDecimal.getText()); update(); }); tfHex.setOnAction(e -> { integer = Integer.parseInt(tfHex.getText(), 16); update(); }); tfBinary.setOnAction(e-> { integer = Integer.parseInt(tfBinary.getText(), 2); update(); }); } private void update() { tfDecimal.setText(integer.toString()); tfHex.setText(Integer.toHexString(integer)); tfBinary.setText(Integer.toBinaryString(integer)); } } public static void main(String[] args) { Application.launch(args); } }
Exercise16 05 Dedmal Hex Binary 15Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started