Please Check My Code and Give Advice..

Hi all.... I am new in Java Programming and need your help for the following :
Convert binary numbers to decimal.
The program should prompt user to enter the number. Upon clicking the button, the program should display the number, the positional wightage of each digit of the number ( I have done some researched n found that i have to use pow method for this....is this correct??? ) .........and the decimal equivalent of the number.
I know how to convert binary to decimal...octal to decimal ... and vice versa as I have learned that prior taking this java programming class.
And I have no difficulty creating buttons n labels....that's the easiest part.
What I don't know is how to use the pow method for the conversion part as I am not gonna have any fix number....user will type lets say...01001 or 111000 .... so how do i capture the numbers from right to left n convert it to decimal?
I noe the conversion is like :
(0*16) + (1*8) + (0*4) + (0*2) +( 0*1)
and I tried using ifElse statements...but i think there's a much simpler n easier way to do....well...maybe i give u what i've done n can u all can shed some light on where i went wrong...
i m such a dummy in this i need to be knock on the head...
well here goes:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Numberpro extends Applet implements ActionListener
Label first, one, two;
TextField satu, dua;
Button con;
int answer;//number that is entered in the textfield
double a1,a2,a4,a8,a16;//declare the 5 digit binary to decimal conversion power
//example:2^0=1 , 2^1=2 , 2^2=4 , 2^3=8 , 2^4=16
int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,za,zb,zc,zd,ze;
//declare if 00000 , 00001 , 00010 then it becomes.....
String type="binary";//convert binary base to decimal
String type2="octal";//convert octal base to decimal
String type3="";
public void init()
{first=new Label ("Number System");
add(first);
one=new Label ("Enter the number : ");
add(one);
satu=new TextField(9);
add(satu);
satu.addActionListener(this);
two=new Label ("Enter the base system ");
add(two);
dua=new TextField(9);
add(dua);
dua.addActionListener(this);
con=new Button ("Convert");
add(con);
con.addActionListener(this);}
public void actionPerformed(ActionEvent event)
{answer=Integer.parseInt(event.getActionCommand());
repaint();
type3=dua.getText();
repaint();}
public static double pow(int a, int b)
{a1 = Math.pow(2.0, 0.0);
a2 = Math.pow(2.0, 1.0);
a4 = Math.pow(2.0, 2.0);
a8 = Math.pow(2.0, 3.0);
a16 = Math.pow(2.0, 4.0);}
public void paint(Graphics g)
{a=a1;
b=a2;
c=(a2+a1);
d=a4;
e=a4+a1;
f=a4+a2;
g=a4+a2+a1;
h=a8;
i=a8+a1;
j=a8+a2;
k=a8+a2+a1;
l=a8+a4;
m=a8+a4+a1;
n=a8+a4+a2;
o=a8+a4+a2+a1;
p=a16;
q=a16+a1;
r=a16+a2;
s=a16+a2+a1;
t=a16+a4;
u=a16+a4+a1;
v=a16+a4+a2;
w=a16+a4+a2+a1;
x=a16+a8;
y=a16+a8+a1;
z=a16+a8+a2;
za=a16+a8+a2+a1;
zb=a16+a8+a4;
zc=a16+a8+a4+a1;
zd=a16+a8+a4+a2;
ze=a16+a8+a4+a2+a1;}
if (type.equals(type3))
{g.drawString("answer " , 40, 55 );}
if (type=00000)
{g.drawString("Decimal Equivalent " + 0 , 60, 75 );}
else
if (type=00001)
{g.drawString("Decimal Equivalent " + a , 60, 75 );}
else
if (type=00010)
{g.drawString("Decimal Equivalent " + b , 60, 75 );}
else
if (type=00011)
{g.drawString("Decimal Equivalent " + c , 60, 75 );}
else
if (type=00100)
{g.drawString("Decimal Equivalent " + d , 60, 75 );}
else
if (type=00101)
{g.drawString("Decimal Equivalent " + e , 60, 75 );}
else
if (type=00110)
{g.drawString("Decimal Equivalent " + f , 60, 75 );}
else
if (type=00111)
{g.drawString("Decimal Equivalent " + g , 60, 75 );}
else
if (type=01000)
{g.drawString("Decimal Equivalent " + h , 60, 75 );}
else
if (type=01001)
{g.drawString("Decimal Equivalent " + i , 60, 75 );}
else
if (type=01010)
{g.drawString("Decimal Equivalent " + j , 60, 75 );}
else
if (type=01011)
{g.drawString("Decimal Equivalent " + k , 60, 75 );}
else
if (type=01100)
{g.drawString("Decimal Equivalent " + l , 60, 75 );}
else
if (type=01101)
{g.drawString("Decimal Equivalent " + m , 60, 75 );}
else
if (type=01110)
{g.drawString("Decimal Equivalent " + n , 60, 75 );}
else
if (type=01111)
{g.drawString("Decimal Equivalent " + o , 60, 75 );}
else
if (type=10000)
{g.drawString("Decimal Equivalent " + p , 60, 75 );}
else
if (type=10001)
{g.drawString("Decimal Equivalent " + q , 60, 75 );}
else
if (type=10010)
{g.drawString("Decimal Equivalent " + r , 60, 75 );}
else
if (type=10011)
{g.drawString("Decimal Equivalent " + s , 60, 75 );}
else
if (type=10100)
{g.drawString("Decimal Equivalent " + t , 60, 75 );}
else
if (type=10101)
{g.drawString("Decimal Equivalent " + u , 60, 75 );}
else
if (type=10110)
{g.drawString("Decimal Equivalent " + v , 60, 75 );}
else
if (type=10111)
{g.drawString("Decimal Equivalent " + w , 60, 75 );}
else
if (type=11000)
{g.drawString("Decimal Equivalent " + x , 60, 75 );}
else
if (type=11001)
{g.drawString("Decimal Equivalent " + y , 60, 75 );}
else
if (type=11010)
{g.drawString("Decimal Equivalent " + z , 60, 75 );}
else
if (type=11011)
{g.drawString("Decimal Equivalent " + za , 60, 75 );}
else
if (type=11100)
{g.drawString("Decimal Equivalent " + zb , 60, 75 );}
else
if (type=11101)
{g.drawString("Decimal Equivalent " + zc , 60, 75 );}
else
if (type=11110)
{g.drawString("Decimal Equivalent " + zd , 60, 75 );}
else
if (type=11111)
{g.drawString("Decimal Equivalent " + ze , 60, 75 );}
I have another question for you too:
1) For the TextField can i use ActionListener instead of TextListener....will it still work?

Couple of things I'd like to mention:
1. Your code is buggy. You need to repair it a lot.
2. You posted the question on the wrong forum. I can't find anything to do with a JSP.
***Annie***

Similar Messages

  • Re: Need help with this assignment. Please see my code and give me tips/advice.

    And your question is?
    My comment so far is:
    You need to be specific in your questions and use code tags.

    And your question is?
    My comment so far is:
    You need to be specific in your questions and use
    code tags.My comment so far is:
    Start coding...

  • Please see my code and give me idea

    Hi master;
    first i use F2-key event and put only this code
    go_block(‘emp’);
    Execute_query;
    but system give me this error FRM-41008 then i use
    on-error event but no result
    Sir I use this code on-error event
    DECLARE errnum NUMBER := ERROR_CODE;
    errtxt VARCHAR2(80) := ERROR_TEXT;
    errtyp VARCHAR2(3) := ERROR_TYPE;
    BEGIN IF errtyp=’FRM’ and errnum = 41008 THEN
    go_block(‘emp’);
    Execute_query;
    END IF;
    END;
    sir give me idea
    Aamir

    Aamir, you asked this same question in the thread below, and I provided an answer.
    how use F2-key

  • Please check the code

    I AM TRYING TO REPLICATE THE ADDRESS OF EQUIPMENT FROM ECC TO CRM.
    I AM ABLE TO REPLICATE THE IDENTIFICATION NUMBER.
    WHILE USING THE SAME FUNCTION MODULE FOR ADDRESS, THE ADDRESS IS NOT GETTING REPLICATED.
    PLEASE CHECK THE CODE AND TELL ME WHAT PRE-REQUISITES MUST BE TAKEN INTO CONSIDERATION AND IS THERE ANY MISTAKE FROM ME.
    FULL POINTS WILL BE REWARDED.
    ITS VERY VERY URGENT.
    METHOD IF_EX_CRM_EQUI_LOAD~ENLARGE_COMPONENT_DATA.
    **Data declarations
    DATA:
        ls_equi          type crmt_equi_mess,
        ls_comp          type ibap_dat1,
        ls_comp_det1     TYPE IBAP_COMP3,
        ls_address_data  type ADDR1_DATA,
        ls_object      type comt_product_maintain_api,
        ls_object1     type comt_product,
        lv_object_id   type IB_DEVICEID,
        lv_object_guid type IB_OBJNR_GUID16.
    **Map Sort field from ECC to CRM
    Read table it_equi_dmbdoc-equi into ls_equi index 1.
    lv_object_id  = ls_equi-equnr.
    move is_object to ls_object.
    move ls_object-com_product to ls_object1.
    lv_object_guid = ls_object1-product_guid.
    move is_component to ls_comp.
    ls_comp_det1-deviceid    = lv_object_id.
    ls_comp_det1-object_guid = lv_object_guid.
    ls_comp_det1-EXTOBJTYP   = 'CRM_OBJECT'.
    ls_comp_det1-ibase       = ls_comp-ibase.
    ls_address_data-roomnumber = '1000'.
    ls_address_data-floor = '10'.
    ls_address_data-country = 'US'.
    CALL FUNCTION 'CRM_IBASE_COMP_CHANGE'
      EXPORTING
       i_comp                       = ls_comp
       I_COMP_DET             = ls_comp_det1
       I_ADDRESS_DATA     = ls_address_data
      I_ADDRESS_ADMIN           =
      I_PARTNER                 =
      I_DATE                    =
      I_TIME                    =
    EXCEPTIONS
      DATA_NOT_CONSISTENT       = 1
      IBASE_LOCKED              = 2
      NOT_SUCCESFUL             = 3
      OTHERS                    = 4
    *IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    ENDMETHOD.

    Hi S B,
    May I the procedure for the replication of serialnumber into device ID that is Identification field In Ibase.
    And one more thing need this to be codded in the standard badi or needed an copy of the implementation .
    plz help me as u already have done the requirement.
    u will be twice rewarded.
    Thanking u in advance for the reply.
    Sree.

  • TS4185 When trying to activate FaceTime I got code,"Could not sign in.Please check network connections and try again".wi fi connection is wall to wall and I can access everything else.Just can't activate facetime.Any ideas?

    When trying to activate FaceTime, get code " Could not sign in.Please check network connections and try again".Wi fi is strong and can access everything else.Any advice?

    Hello
    Try this... I had the same problem and this worked for me.
    Go to your system preferences → network → make sure WI-FI selected → advanced → DNS tab. Add 8.8.8.8 to the DNS servers. Go back to FaceTime and try to verify your account again.
    Good luck!

  • I didnt konw how to make a new account for my iTues card so i did it with a diffrent email but that email doesnt exist and when i tried to make it on a real email i just sai invalid code check the code and try again and can u please help me

    please help me it is a card of 25 dollars and i dont want it to go to waist i by mistake thought you used a frake email so i made one up i thought i was going to have a new one but then it said it was going to send a verifaction to my email so then i tried to use a real email and put in the code but it just kept on saying invalid code. check the code and try again. and i dont know what to do can u please please help me it was a gift and i really dont want it to go to waist please i need help

    for #1
    Frequently asked questions about Apple ID - Apple Support
    I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID?
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.
    If you are wondering how using multiple Apple IDs relate to iCloud, see Apple IDs and iCloud.
    for #2
    Apple does not accept unsolicited ideas see Apple - Legal - Unsolicited Idea Submission Policy

  • When entering my phone serial number it shows "We're sorry, but this is a serial number for a product that has been replaced. Please check your information and re-enter your serial number. If your information is correct, you may need to contact us."

    Hi,
    I had purchased an iPhone 5 last month and got the OS updated to iOS 7, yesterday.
    The data cable was of very bad quality and when I took it to the retailer for replacement, they said that its not covered under the one year warranty.
    Secondly, I have also been experiencing network coverage issues with this phone. So, I decided to contact apple care through the web. When entering my serial number/IMEI it says, "We're sorry, but this is a serial number for a product that has been replaced. Please check your information and re-enter your serial number. If your information is correct, you may need to contact us."
    Does anybody have any idea what the reason behind this could be.
    - First time with iPhone and frustrated.
    Briju

    If you purchased the iPhone from Apple or an authorized Apple reseller,
    contact them for assistance. If you purchased elsewhere, go back
    to that retailer and get them to give you a new iPhone or your money
    back.
    If you have checked the serial number carefully and re-entered it
    and that gave you the same error message, contact Apple if purchased
    from Apple or authorized retailer; otherwise you have been scammed
    and need to pursue the matter with the business you obtained the
    iPhone from.

  • Trouble updating to iOS 5 on my wife's iPhone 4 connected to our iM, right before download finishes downloading iTunes comes back with the error message Software corrupted during download.  Please check network settings and try again later.

    Trouble updating to iOS 5 on my wife's iPhone 4 connected to our iM, right before download finishes downloading iTunes comes back with the error message Software corrupted during download.  Please check network settings and try again later, however there was no problem updating my iPhone to iOS 5 through iTunes connceted to my dell laptop on the same wireless network.  What gives?

    Try disabling your firewall; both on your PC and the external Firewall/Router.

  • When i want to ask the guaranty status of my apple wireless keyboard, i got an error: apple keyboard We're sorry, but this serial number is not valid. Please check your information and try again.

    When i want to ask the guaranty status of my apple wireless keyboard, i got an error: apple keyboard We're sorry, but this serial number is not valid. Please check your information and try again.

    If you purchased the iPhone from Apple or an authorized Apple reseller,
    contact them for assistance. If you purchased elsewhere, go back
    to that retailer and get them to give you a new iPhone or your money
    back.
    If you have checked the serial number carefully and re-entered it
    and that gave you the same error message, contact Apple if purchased
    from Apple or authorized retailer; otherwise you have been scammed
    and need to pursue the matter with the business you obtained the
    iPhone from.

  • IMessage on ML - "Could not sign into iMessage. Please check network settings and try again"

    i came across an issue when signing into iMessage with an Apple ID on Mac.
    i had been experiencing the "Could not sign into iMessage. Please check network setting and try again" error for iMessage issue since installing Mountain Lion. i finally solved my problem after talking to the Apple Tech Support team.
    Here's the steps:
    1. Shut down laptop.
    2. Switch on laptop again. immediately hold down the left "SHIFT" key until u get into the log in screen. By doing this, ur laptop will be in "Safe Boot" mode.
    3. Sign into iMessage using Apple ID. (i was able to sign into iMessage for the first time on my Mac since getting ML)
    4. Shut down laptop again.
    5. This time switch laptop on normally.
    6. You should be able to use iMessage normally.
    in addition, make sure the boxes for date & time and timezone are ticked to be set automatically.
    Hope this is helpful for users experiencing the same issue i had. it did for me!
    Cheers

    Okay,
    let me add my story to this thread.
    Brand spanking MBA, Mountain Lion.......logged into Imessage 1st thing, no prob.
    Then, after a few weeks; in the middle of a chat....the name of the other person turned red and my sent messages received a red dot as they were not sent. I checked with the other person.
    I couldn`t recieive any messages either, not from any contact.
    I logged out, and I couldn`t log in anymore.
    I get a yellow triangle saying something like "error while logging in, try again later".
    I tried again and again later........
    I seeked help on this forum and a user helped me initially.
    I re-installed the whole Mountain Lion, a process that I don`t care to repeat too often.
    That fixed it for a while, but yesterday the same thing happened.
    In the middle of a chat....the red name, the red dots......well, you get the picture.
    I tried, to no avail:
    # to log in after reseting the PRAM
    # boot up and log in whilst in SAVE mode. It will NOT log in, same problem
    # to log in after deleting all Imessages and Facetime files in Library/Preferences
    # to log in with my wife`s Apple ID, or any ID really.
    What did work was logging in with my ID on my wife`s Ipad, no worries.
    My account is Yahoo, and don`t seem to be the problem.
    Please, any suggestions welcome.
    I have urged Apple politley to give us a fix at:
    http://www.apple.com/feedback/
    Thanks,
    MXP 150 Patriot

  • Unable to reach Adobe servers, Please check firewall settings and try again

    I have been a creative cloud customer since it started and I've never experienced such buggy software as the app manager. The customer experience is just shocking and I wish Adobe would just offer direct downloads for the software we need rather than use the app manager.
    I'm currently trying to install the latest versions of the programs but the app manager keeps showing "Unable to reach Adobe servers, Please check firewall settings and try again in a few minutes".
    I do not have any firewalls on my network.
    I've uninstalled all previous versions of the applications.
    The app manager will download a few % and then the message appears again. I click retry and it downloads another few % before showing the message again. I keep doing this until the program is fully downloaded and installed which take hours. Because I am able to eventually download the app, the error should be anything to do with my setup or internet connection as I've never had this issue before when installing adobe products.
    Is there a way we can bypass the app manager and install the programs directly? This is getting very annoying and I just need my apps to install without wasting days clicking the retry button.

    I'm having the exact same problem. Photoshop is stuck at 0%.
    Have the links for direct download changed? When I went to  http://prodesigntools.com/adobe-cc-direct-download-links.htmland then scrolled down the page to:
    Photoshop CC 2014 (64-bit)
    740 MB
    File 2
    801 MB
    File 1
    and then clicked on File 1 and File 2, I reached a page that says "You don't have permission to access "http://trials3.adobe.com/AdobeProducts/PHSP/15/win64/Photoshop_15_LS20_win64.7z?" on this server."

  • TS4006 my mobile was stolen 2days before. please find my iphone and give the location. my mobile IMEI Number is - 012854005421769

    Dear Sir,
    my mobile was stolen 2days before. please find my iphone and give the location.
    my mobile IMEI Number is - > 012854005421769
    this is my mobile user name - > VINOTH P
    country  - > india
    state - > tamil nadu
    City - > chennai
    Mobile Phone Bill Details :
    Apple Iphn 8gb #GS Airtel BLK
    166104 U4
    CSH N N  Purchasing Date ( 01-01-2012 )
    Please i am very critical situation now, My Business is very down. please help me sir.

    You aren't talking to Apple here. This is a user to user technical help forum.
    Apple will not find your phone.

  • I have Photoshop CS6 Extended Students and Teachers Edition.  When I go into the Filter/Oil paint and try to use Oil paint a notice comes up "This feature requires graphics processor acceleration.  Please check Performance Preferences and verify that "Use

    I have Photoshop CS6 Extended Students and Teachers Edition.  when I go into the Filter/Oil paint and try to use Oil Paint a notice comes up "This feature requires graphics processor acceleration.  Please Check Performance Preferences and verify that "Use Graphics Processor" is enabled.  When I go into Performance Preferences I get a notice "No GPU available with Photoshop Standard.  Is there any way I can add this feature to my Photoshop either by purchasing an addition or downloading something?

    Does you display adapter have a supported  GPU with at least 512MB of Vram? And do you have the latest device drivers install with Open GL support.  Use CS6 menu Help>System Info... use its copy button and paste the information in here.

  • Trying to Hot Sync Visor Pro with Windows 7 (64 bit OS) - getting error: "The connection between your handheld computer and the destktop could not be establishe​d. Please check your setup and try again."

    Hi.
    I read the posting regarding the options on Hotsyncing for Windows 7; however, I have some questions as I have a 64-bit system.
    I have a Visor Pro that I'm trying to Sync up with my new laptop which is running Windows 7.
    Steps I have taken:
    * installed the Visor Palm Desktop 3.0.1 that came with the Visor (which the installation went well)
    * The issue arises when I push the "Sync" button on the cradle and the following error message appears "The connection between your handheld computer and the destktop could not be established.  Please check your setup and try again."
    Since I have a 64-bit OS it appears that I have 2 options: 1) bluetooth or 2) Infrared.
    I have to admit I don't know know how to do either of these (how can I tell if this Handspring Visor Pro has bluetooth (which I don't it does)?). 
    Then how about the Infrared option?  I see on the PDA it has a red area that one can "beam" info.  Is this the same as Infrared or my 2nd option?
    I love my Visor and want to continue using it, but need to backup the valuable info!
    Any help with this would be greatly appreciated!
    THANKS!!!!!
    Post relates to: Visor Pro

    Hello lwalbring and welcome to the Palm forums.
    Your Visor, as you suspect, does not have Bluetooth, so you must use the IR HotSync option.  Since you are using Windows 7 64-bit, I believe that you are going to have to upgrade to Palm Desktop 6.2.2 to make things work from an OS/Driver perspective.
    Since you are using such an old device, you are also going to have to download and install the PalmHotSyncSetup Utility from Pimlico.  This update turns on support for old Palm OS PDAs in Palm Desktop 6.2.2.  Without the update, you won't be able to sync your Visor with Palm Desktop 6.2.2.  The software is free and the link is all the way at the bottom of the screen.
    Lastly, if your PC doesn't have an IR port on it, you will need to purchase a USB to IR adapter.  Some laptops still have IR ports and most desktops don't.
    Once you have all the pieces, you'll want to go back to the Windows 7 and Vista HotSync thread again, and follow the directions for setting up and configuring IR HotSyncs.
    Alan G

  • PO creation-ME21n-Why SAP does not check company code and Plant relation

    Hi All,
    Does someone know, why SAP does not check Plant and company code relation at the time of PO creation or how can we put validation between plant and company code at the time of PO creation.
    <b>Example:</b> Suppose i have a company 0001 which is assinged to Plant 0001. when i am creating a PO with another company code 0002(Entering at header level-Org, data) and using Plant 0001 at line item level. SAP does not do this validation.
    How can we put this check in place?
    Thanks in advance.
    Deepak

    Hello Deepak,
    There are three types of purchasing
    - Company code specific :You need to assign company code to Pur organization
    - Plant specific : You must assign plant to pur organization
    - Cross company purchasing: No assignment between company code and pur organization.
    In the case 3, the system will not check company code and plant relationship, but it will check plant and pur organization specific.
    The following is the copy of sap help text:
    You can assign a purchasing organization to one company code. This is company-specific purchasing.
    You can assign a purchasing organization to no company code. This purchasing organization can then procure for all plants assigned to it, irrespective of the company code to which the plant belongs.
    Since each plant must be assigned to a company code, the company code can be determined via the plant in each procurement transaction, even if the procuring purchasing organization is not assigned to a company code.
    A purchasing organization must be assigned to one or more plants. This is plant-specific purchasing.
    Now, check your company-code and purchase organization assignment.
    Hope this helps.
    Regards
    Arif Mansuri

Maybe you are looking for