So my java pprgram is actually a GUI I did all of it except I cant figure out how to convert between bases example:
number=2239
base=3
newbase=4
first i need to convert 2239 to base 3 which would be
2 * 3^3 + 2* 3^2 + .....
then convert that number to base 4
whatever base 3 equals %4 until i is <=base
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class Assignment3_2 extends JFrame
{
private JLabel NumberL, OriginalBaseL, NewBaseL, NewNumberL;
private JTextField NumberTF, OriginalBaseTF, NewBaseTF, NewNumberTF;
private JButton CalculateB, ExitB;
private CalculateButtonHandler cbHandler;
private ExitButtonHandler ebHandler;
private static final int WIDTH = 500;
private static final int HEIGHT = 300;
public Assignment3_2()
{
NumberL = new JLabel("Enter the Original Number: ",SwingConstants.RIGHT);
OriginalBaseL = new JLabel("Enter the Original Base: ",SwingConstants.RIGHT);
NewBaseL = new JLabel("Enter the Base to change the number into: ",SwingConstants.RIGHT);
NewNumberL = new JLabel("Number with Base Changed: ",SwingConstants.RIGHT);
NumberTF = new JTextField(10);
OriginalBaseTF = new JTextField(10);
NewBaseTF = new JTextField(10);
NewNumberTF = new JTextField(10);
CalculateB = new JButton("Calculate");
cbHandler = new CalculateButtonHandler();
CalculateB.addActionListener(cbHandler);
ExitB = new JButton("Exit");
ebHandler = new ExitButtonHandler();
ExitB.addActionListener(ebHandler);
setTitle("Base Conversion");
Container pane = getContentPane();
pane.setLayout(new GridLayout(5,2));
pane.add(NumberL);
pane.add(NumberTF);
pane.add(OriginalBaseL);
pane.add(OriginalBaseTF);
pane.add(NewBaseL);
pane.add(NewBaseTF);
pane.add(NewNumberL);
pane.add(NewNumberTF);
pane.add(CalculateB);
pane.add(ExitB);
setSize(WIDTH,HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class CalculateButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double Number, OriginalBase, NewBase, NewNumber,tempbase;
Number = Double.parseDouble(NumberTF.getText());
OriginalBase = Double.parseDouble(OriginalBaseTF.getText());
NewBase = Double.parseDouble(NewBaseTF.getText());
tempbase+= (original%4)
for( int i=0;i<=Originalbase; i++)
NewNumberTF.setText("" + NewNumber);
}
}
private class ExitButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main(String[] args)
{
Assignment3_2 baseObject = new Assignment3_2();
}
}
how would I find the newbase? would I do something like:
tempbase+= (original%4)
for( int i=0;i<=Originalbase; i++)