I need to build a number conversion calculator that has a GUI . It converts numb
ID: 3722751 • Letter: I
Question
I need to build a number conversion calculator that has a GUI . It converts numbers between hex, binary, octal and decimal. The calculator has to perform arithmetics such as (+,-,*,/) as well. I do not want to use any python built in library , i need a clear shown step by step conversion. I've only managed to do a step by step conversion of decimal to binary.. and am pretty lost here ... Unable to use builtin python conversion functions and needs to show the steps is whats hard about this. can someone help me. The attached photo is how i want my gui to kinda look like
Python : dec to binary
def main():
#get input from user
n = int(input("Enter a decimal number:"))
#print output
print("{0} in decimal = {1} in binary".format(n,DecToBin(n)))
return 0
def DecToBin(n):
binaryNumber = 0;remainder = 1;i=1;step=1;
while(n!=0):
#get remainder
remainder = n%2
print("Step{0}:{1}/2,Quotient={2},Remainder ={3} ".format(step, n,int(n/2),remainder))
#increment
step += 1
#get integer part of n/2
n = int(n/2)
#add remainder to binaryNumber
binaryNumber += remainder * i
i *= 10
return binaryNumber
main()
Dec Hex + Oct Bin DEL 9 ACExplanation / Answer
package finalConverter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Converter extends JFrame {
private JTextField textField;
private JButton convert;
private JLabel hexadecimal, binary, decimal;
public Converter() {
setTitle("Converter");
setSize(400,400);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(new ConverterPanel());
}
protected class ConverterPanel extends JPanel{
public ConverterPanel(){
setLayout(new GridLayout(3,5));
textField = new JTextField();
convert = new JButton ("Convert");
hexadecimal = new JLabel("Hexadecimal");
binary = new JLabel ("Binary");
decimal = new JLabel ("Decimal");
add(hexadecimal);
add(textField);
add(convert);
add(binary);
add(decimal);
}
}
protected class EventHandler implements ActionListener{
public void actionPerformed(ActionEvent ev){
if(ev.getSource() == convert){
double result = ()
}
}
}
public static void main(String[] args) {
new Converter().setVisible(true);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.