Results 1 to 2 of 2
  1. #1
    j@y is offline Member
    Join Date
    Oct 2011
    Rep Power

    Default Code to convert binary number to base 10 number

    Hello, I'd like help converting a binary number to a base 10 number using a loop statement. I've tried to no success to do it myself.

    Here is the problem in its entirety, though I'm having trouble with that one specific part.

    Write a Java project (Applet) with two classes. In the init() method of the driver class, use a sentinel controlled loop to enter binary numbers via Input Dialog boxes. (When a value of -1 is entered, you should exit the loop)

    In the init() method, you should also declare a variable to be of type Binary. Inside the while loop, you should invoke the convert method of the Binary class. This method converts the binary number you entered, into a base 10 number. These base 10 numbers should be counted and accumulated.

    Each binary number and its converted base 10 number should be appended to a JTextArea. The value of the counter, the value of the accumulator, and the mean of the base 10 numbers should also be appended to the JTextArea. The JTextArea should be attached to a Container.

    In the Binary class, there should be one instance field of type String. The parametric constructor accepts a String argument (the binary number) and assigns it to the instance field. The parametric constructor is the only constructor needed. The convert method uses the instance field to determine and return an integer (the base 10 number). Inside this method, a while loop should be used to convert the binary to decimal, one digit at a time.

    Thank you for your help

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Code to convert binary number to base 10 number

    Help with what? You haven't asked us a question, you just showed us your assignment (emphasis on 'your').

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. All possible combinations given a binary number
    By LeanA in forum New To Java
    Replies: 9
    Last Post: 06-18-2010, 06:33 PM
  2. convert number to string
    By wizard_oz in forum New To Java
    Replies: 9
    Last Post: 11-16-2009, 08:04 PM
  3. how to convert String number to int
    By gabriel in forum New To Java
    Replies: 5
    Last Post: 08-02-2009, 04:46 PM
  4. Convert bar code to number
    By samatha_kudi in forum Advanced Java
    Replies: 1
    Last Post: 07-17-2009, 03:56 PM
  5. Converts a binary number to a decimal
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 10:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts