base conversion

Here's my codes:
import java.io.*;
import javax.swing.*;
import java.util.*;
import java.math.*;
import java.awt.*;
import java.awt.event.*;

public class Conversion extends JFrame
{
      private JLabel oldNumLabel;
      private JLabel newNumLabel;
      private JLabel oldBaseLabel;
      private JLabel newBaseLabel;
      private JTextField oldNumTF;
      private JTextField newNumTF;
      private JTextField oldBaseTF;
      private JTextField newBaseTF;
      private JButton conversionB;
      private JButton exitB;
      private ConversionButtonHandler cbHandler;
      private ExitButtonHandler ebHandler;
      
      public static final int WIDTH = 400;
      public static final int HEIGHT = 300;
      
      public Conversion()
      {
            //Creates four lables
            oldNumLabel = new JLabel("Enter a positive integer: ", SwingConstants.RIGHT);
            oldBaseLabel = new JLabel("Enter a base for the positive integer: ", SwingConstants.RIGHT);
            newBaseLabel = new JLabel("Enter the new base for the positive integer: ", SwingConstants.RIGHT);
            newNumLabel = new JLabel("Result: ", SwingConstants.RIGHT);
            
            //Creates four text fields
            oldNumTF = new JTextField(10);
            oldBaseTF = new JTextField(10);
            newBaseTF = new JTextField(10);
            newNumTF = new JTextField(10);
            
            //Creates Conversion Button
            conversoinB = new JButton("Convert");
            cbHandler = new ConversionButtonHandler();
            conversionB.addActionListener(cbHandler);
            
            //Creates Exit Button
            exitB = new JButton("Exit");
            ebHandler = new ExitButtonHandler();
            exitB.addActionListener(ebHandler);
            
            //Sets the title of the window
            setTitle("Base Conversion");
            
            //Sets the container
            Container pane = getContentPane();
            
            //Sets the layout
            pane.setLayout(new GridLayout(4,2));
            
            //Places the components in the pane
            pane.add(oldNumLabel);
            pane.add(oldBaseLabel);
            pane.add(newBaseLabel);
            pane.add(newNumLabel);
            pane.add(oldNumTF);
            pane.add(oldBaseTF);
            pane.add(newBaseTF);
            pane.add(newNumTF);
            pane.add(conversionB);
            pane.add(exitB);
            
            //Sets the size of the window and display it
            setSize(WIDTH,HEIGHT);
            setVisible(true);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
      }
      
      private class ConversionButtonHandler implements ActionListener
      {
            public void actionPerformed(ActionEvent e)
            {
                  //declares variables
                  int oldNum, oldBase, newBase, newNum, counter, numDigits;
                  double temp;
                  int interSum = 0;
                  
                  oldNum = Integer.parseInt(oldNumTF.getText());
                  oldBase = Integer.parseInt(oldBaseTF.getText());
                  newBase = Integer.parseInt(newbaseTF.getText());
                  
                  if ((oldBase < newBase) || (newBase > oldBase))
                  {
                        for(numDigits--; (numDigits = Math.log(oldNum) / Math.log(10) + 1);
                              numDigits = 0)
                        {
                              //get the first digit
                              temp = oldNum / Math.pow(10,numDigits);
                              //find out the sum of individual digits times its base power
                              intermSum = intermSum + temp * (Math.pow(oldBase,numDigits));
                              //get the digits remained after previous executions
                              temp = temp % (Math.pow(10,numDigits));
                        }
                        
                        temp = intermSum % newBase;
                              
                        int quotient = interSum / newBase;
                        
                        private class ExitButtonHandler implements ActionListener
                        {
                              public void actionPerformed(ActionEvent e)
                              {
                                    System.exit(0);
                              }
                        }
                  }
                  
                  
            }
      }
      
      public static void main(String[] args)
                  {
                        BaseConversion baseObject = new BaseConversion();
                  }
}

there are about 12 errors, but I just don't know how to fix.
please compile this java first.

thanks
crystalfish0318Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

harris_cCommented:
Combine ButtonHandlers.


Best is let a GUI do the formatting/setting for you and edit it afterwards.

import java.io.*;
import javax.swing.*;
import java.util.*;
import java.math.*;
import java.awt.*;
import java.awt.event.*;

public class Converstion extends JFrame
{
    private JLabel oldNumLabel;
    private JLabel newNumLabel;
    private JLabel oldBaseLabel;
    private JLabel newBaseLabel;
    private JTextField oldNumTF;
    private JTextField newNumTF;
    private JTextField oldBaseTF;
    private JTextField newBaseTF;
    private JButton conversionB;
    private JButton exitB;

    public static final int WIDTH = 400;
    public static final int HEIGHT = 300;

    public Converstion()
    {
         //Creates four lables
         oldNumLabel = new JLabel("Enter a positive integer: ", SwingConstants.RIGHT);
         oldBaseLabel = new JLabel("Enter a base for the positive integer: ", SwingConstants.RIGHT);
         newBaseLabel = new JLabel("Enter the new base for the positive integer: ", SwingConstants.RIGHT);
         newNumLabel = new JLabel("Result: ", SwingConstants.RIGHT);

         //Creates four text fields
         oldNumTF = new JTextField(10);
         oldBaseTF = new JTextField(10);
         newBaseTF = new JTextField(10);
         newNumTF = new JTextField(10);

         //Creates Conversion Button
         conversionB = new JButton("Convert");

         //Creates Exit Button
         exitB = new JButton("Exit");
         
              //{{REGISTER_LISTENERS
             SymAction lSymAction = new SymAction();
             conversionB.addActionListener(lSymAction);
             exitB.addActionListener(lSymAction);
             //}}
         

         //Sets the title of the window
         setTitle("Base Conversion");

         //Sets the container
         Container pane = getContentPane();

         //Sets the layout
         pane.setLayout(new GridLayout(4,2));

         //Places the components in the pane
         pane.add(oldNumLabel);
         pane.add(oldBaseLabel);
         pane.add(newBaseLabel);
         pane.add(newNumLabel);
         pane.add(oldNumTF);
         pane.add(oldBaseTF);
         pane.add(newBaseTF);
         pane.add(newNumTF);
         pane.add(conversionB);
         pane.add(exitB);

         //Sets the size of the window and display it
         setSize(WIDTH,HEIGHT);
         setVisible(true);
   
            //{{INIT_CONTROLS
            setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
            setVisible(true);
            //}}
      }

      class SymAction implements java.awt.event.ActionListener
    {
            public void actionPerformed(java.awt.event.ActionEvent event)
            {
                  Object object = event.getSource();
                  if (object == conversionB)
                        conversionB_actionPerformed(event);
                  else if (object == exitB)
                        exitB_actionPerformed(event);
            }
      }

      void conversionB_actionPerformed(java.awt.event.ActionEvent event)
      {
            // to do: code goes here.

         //declares variables
              int oldNum, oldBase, newBase, newNum, counter;
              double numDigits;
              double temp;
              double intermSum = 0;

              oldNum = Integer.parseInt(oldNumTF.getText());
              oldBase = Integer.parseInt(oldBaseTF.getText());
              newBase = Integer.parseInt(newBaseTF.getText());

              if ((oldBase < newBase) || (newBase > oldBase))
              {
                    numDigits = (Math.log(oldNum) / Math.log(10) + 1);
                   
                    while (numDigits != 0)
                   {
                        //get the first digit
                        temp = oldNum / Math.pow(10,numDigits);
                        //find out the sum of individual digits times its base power
                        intermSum = intermSum + temp * (Math.pow(oldBase,numDigits));
                        //get the digits remained after previous executions
                        temp = temp % (Math.pow(10,numDigits));
                        numDigits--;
                   }

              temp = intermSum % newBase;

              int quotient = (int)intermSum / newBase;
              }
         }
         
      void exitB_actionPerformed(java.awt.event.ActionEvent event)
      {
            // to do: code goes here.
        System.exit(0);
    }
 
    public static void main(String[] args)
              {
                   Converstion baseObject = new Converstion();
                   baseObject.show();
              }


hec",)
0
crystalfish0318Author Commented:
when i click the "convert" button, it stuck.................
0
crystalfish0318Author Commented:
when i click the "convert" button, it stuck.................

my inupt is:
number = 2010, base = 3 and new base = 4.

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

crystalfish0318Author Commented:
wait, did i miss anything?

ok, here's the question:
Design and implement a GUI program to convert a positive number given in one base to another base. For this problem, assume that both bases are less than or equal to 10.

if
number = 2010, base = 3 and new base = 4

then the first thing is to convert 2010 in base 3 into the equivalent number in base 10 as follows:
2*3^3 + 0*3^2 + 1*3 + 0 = 54 + 0 + 3 + 0 = 57

To convert 57 to base 4, i find the remainders obtained by dividing by 4, as shown in the following:

57 % 4 = 1, quotient = 14
14 % 4 = 2, quotient = 3
3 % 4 = 3, quotient = 0.
Therefore, 57 in base 4 is 321.
0
crystalfish0318Author Commented:
is my while loop correct? how can i output the result correctly?
0
grim_toasterCommented:
Your algorithm seems a bit more complicated than needed!  You can use the standard Java libraries to do most of what you're after (why re-invent the wheel?)

Use Integer.parseInt(String, radix) to parse your text field input to an int, and then use Integer.toString(int, radix) to return the String representation of the new radix.  I'll leave it up to you to look into the API's for the details on the min and max radix values.  But are you sure that you will only ever be dealing with ints?
0
crystalfish0318Author Commented:
import java.io.*;
import javax.swing.*;
import java.util.*;
import java.math.*;
import java.awt.*;
import java.awt.event.*;

public class ch6_num9 extends JFrame
{
      private JLabel oldNumLabel;
    private JLabel newNumLabel;
    private JLabel oldBaseLabel;
    private JLabel newBaseLabel;
    private JTextField oldNumTF;
    private JTextField newNumTF;
    private JTextField oldBaseTF;
    private JTextField newBaseTF;
    private JButton conversionB;
    private JButton exitB;
   

    public static final int WIDTH = 600;
    public static final int HEIGHT = 300;

    public ch6_num9()
    {
          
        //Creates four lables
        oldNumLabel = new JLabel("Enter a positive integer: ", SwingConstants.RIGHT);
        oldBaseLabel = new JLabel("Enter a base for the positive integer: ", SwingConstants.RIGHT);
        newBaseLabel = new JLabel("Enter the new base for the positive integer: ", SwingConstants.RIGHT);
        newNumLabel = new JLabel("Result: ", SwingConstants.RIGHT);

        //Creates four text fields
        oldNumTF = new JTextField(10);
        oldBaseTF = new JTextField(10);
        newBaseTF = new JTextField(10);
        newNumTF = new JTextField(10);

        //Creates Conversion Button
        conversionB = new JButton("Convert");


        //Creates Exit Button
        exitB = new JButton("Exit");
      
         
         //REGISTER_LISTENERS
         SymAction lSymAction = new SymAction();
         conversionB.addActionListener(lSymAction);
         exitB.addActionListener(lSymAction);
         //***********
         

         //Sets the title of the window
         setTitle("Base Conversion");

         //Sets the container
         Container pane = getContentPane();

         //Sets the layout
         pane.setLayout(new GridLayout(4,2));

         //Places the components in the pane
             pane.add(oldNumLabel);
                pane.add(oldNumTF);
               
             pane.add(oldBaseLabel);
                pane.add(oldBaseTF);
               
             pane.add(newBaseLabel);
                pane.add(newBaseTF);
               
             pane.add(newNumLabel);
                pane.add(newNumTF);
                     
               
             pane.add(conversionB);
               pane.add(exitB);

         //Sets the size of the window and display it
             setSize(WIDTH,HEIGHT);
           setVisible(true);
             setDefaultCloseOperation(EXIT_ON_CLOSE);
   
         //INIT_CONTROLS
         setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
         setVisible(true);
         //********************************
    }

      class SymAction implements java.awt.event.ActionListener
    {
          public void actionPerformed(java.awt.event.ActionEvent event)
        {
              Object object = event.getSource();
              
            if (object == conversionB)
            conversionB_actionPerformed(event);
           
            else
            if (object == exitB)
            exitB_actionPerformed(event);
        }
    }

    void conversionB_actionPerformed(java.awt.event.ActionEvent event)
      {
            // to do: code goes here.

        //declares variables
        int oldNum, oldBase, newBase, newNum, counter;
        double numDigits;
        double temp;
        double intermSum = 0.0;

        oldNum = Integer.parseInt(oldNumTF.getText());
        oldBase = Integer.parseInt(oldBaseTF.getText());
        newBase = Integer.parseInt(newBaseTF.getText());

        if ((oldBase < newBase) || (newBase > oldBase))
        {
              numDigits = (Math.log(oldNum) / Math.log(10) + 1);
           
            while (numDigits != 0)
            {
                  //get the first digit
                temp = oldNum / Math.pow(10,numDigits);
               
                //find out the sum of individual digits times its base power
                intermSum = intermSum + temp * (Math.pow(oldBase,numDigits));
               
                //get the digits remained after previous executions
                temp = temp % (Math.pow(10,numDigits));
                numDigits--;
            }

            temp = intermSum % newBase;

            int quotient = (int)intermSum / newBase;
            }
      }
         
    void exitB_actionPerformed(java.awt.event.ActionEvent event)
    {
          // to do: code goes here.
        System.exit(0);
    }
 
    public static void main(String[] args)
    {
          ch6_num9 baseObject = new ch6_num9();
        baseObject.show();
    }
}

the position of my converter is just not right.............
0
grim_toasterCommented:
The problem lies in your conversionB_actionPerformed method.  One of the problems is that you hold the number of digits in a primitive double type, and then loop to see if not equal to 0, looping to see if greater than 0 would have been better, as on my machine I had a value of 4.1224322 (or something like that), and subtracting one each time, it would never be zero!.

Here's a simpler version of the method:
    void conversionB_actionPerformed(java.awt.event.ActionEvent event)
    {
        int oldBase = Integer.parseInt(oldBaseTF.getText());
        int newBase = Integer.parseInt(newBaseTF.getText());

        int oldNum = Integer.parseInt(oldNumTF.getText(), oldBase);
        String newNum = Integer.toString(oldNum, newBase);
        newNumTF.setText(newNum);
    }

And you were never setting the result to the screen!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.