Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(The Swing part of this project is quite straightforward, but you do need to kno

ID: 3625971 • Letter: #

Question

(The Swing part of this project is quite straightforward, but you do need to know a little about how to convert from one base to another.)
--Write a program that coverts numbers from base-10(ordinary decimal) notation to base-2 notation. The program uses Swing to perform input and output via a window interface.
The user enters a base-10 number in one text field and clicks a Convert button. The equivalent base-2 number then appears in another text field. Be sure that the two text fields are labeled. Include a Clear button that clears both text fields when clicked. Also be sure that the close-window button works correctly.

Explanation / Answer

This is the java program to convert from decimal to binary format: toBinaryString() used to vonvert into binary format. Integer.parseInt() used to convert into integer. import java.swing.*; import java.lang.*; import java.io.*; public class DToB{ public static void main(String args[]) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Pls enter the decimal value:"); String hex = bf.readLine(); int i = Integer.parseInt(hex); String by = Integer.toBinaryString(i); System.out.println("Binary: " + by); } } and think this also... I am not sure though how you will actually output it in a SINGLE loop considering that the logical way of converting the number from one base to another is from right to left (from least significant to most significant digits) and the ONLY way to output it is left to right... So, maybe you are allowed to use something else, NOT just a loop?