Incorporate: For, and while loop,a nested pair for both,and to add graphics

// I have done the class but
need help one adding one while loop, one for loop, and a nested pair loops using for and while, and if posbile to add on a dynamite graphics. // i am doing this for a brithday present for my brother who is a java programer
and would be happy to see his little brother make a java programe for him
//class file
import java.awt.*;
public class ZZZCalculator
        private double amount;
        public ZZZCalculator (double x)
                amount= x;
        public void addAmt (double inputNumber)
                amount= amount +inputNumber;
        public void divideAmt (double inputNumber)
                amount=amount/inputNumber;
        public void subtractAmt (double inputNumber)
                amount=amount-inputNumber;
        public void multiplyAmt (double inputNumber)
                amount=amount*inputNumber;
        public void display (Graphics g)
                g.drawString (""+ amount, 150,100);
        public void setAmt(double x)
                amount= x;
  // Pgm file
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class ZZZCalc extends Applet implements ActionListener {
        ZZZCalculator henrietta;
        TextField amtPlace;
        Button adder;
        Button divide;
        Button subtract;
        Button multiply;            
        public void init()
                henrietta=new ZZZCalculator(0.0);
                amtPlace=new TextField(10);
                amtPlace.addActionListener(this);
                add(amtPlace);
                adder=new Button ("+");
                adder.addActionListener(this);
                add(adder);
                divide=new Button ("/");
                divide.addActionListener(this);
                add(divide);
                subtract=new Button ("-");
                subtract.addActionListener(this);
                add(subtract);
                multiply=new Button ("*");
                multiply.addActionListener(this);
                add(multiply);
        public void paint (Graphics g)
                g.drawString("amount:", 100,100);
                henrietta.display(g);
        public void actionPerformed(ActionEvent e)
                if (e. getSource()==amtPlace)
                double amt= Double.parseDouble (amtPlace.getText());
                henrietta.setAmt(amt);
                repaint();
                if(e.getSource()==adder)
                double amt= Double.parseDouble (amtPlace.getText());
                henrietta.addAmt(amt);
                repaint();
                if(e.getSource()==divide)
                double amt= Double.parseDouble (amtPlace.getText());
                henrietta.divideAmt(amt);
                repaint();
                if(e.getSource()==subtract)
                double amt= Double.parseDouble (amtPlace.getText());
                henrietta.subtractAmt(amt);
                repaint();
                if(e.getSource()==multiply)
                double amt= Double.parseDouble (amtPlace.getText());
                henrietta. multiplyAmt(amt);
               repaint();
//thank you for the help
i have just started working on java and this is my frist program i am working on and any help i can get would inprove my understanding of java.
Thank you very much for you help

hey there... this is Rebecca
try this somewhere in the prog.
n = Math.pow(x,y)
where n is an int you declare...
and x and y are the numbers... as in
n = 10^3
where 10 = x and 3 = y

Similar Messages

  • How to code a parallel 'for loop' and 'while loop' where the while loop cannot terminate until the for loop has finished?? (queues also present)

    I've attached a sample VI that I just cannot figure out how to get working the way that I want.  I've labeled the some sections with black-on-yellow text boxes for clarity during the description that follows in the next few sentences.  Here's what I want:
    1) overall -- i'm intend for this to be a subVI that will do data acquisition and write the data to a file.  I want it to use a producer/consumer approach.  The producer construct is the 'parallel for loop' that runs an exact number of times depending on user input (which will come from the mainVI that is not included).  For now I've wired a 1-D array w/ 2 elements as a test case.  During the producer loop, the data is acquired and put into a queue to be delt with in the consumer loop (for now, i just add a random number to the queue).
    2) the consumer construct is the 'parallel while loop'.  It will dequeue elements and write them to a file.  I want this to keep running continuously and parallel until two conditions are met.
          i. the for loop has finished execution
          ii. the queue is empty.
       when the conditions are met, the while loop will exit, close the queue, and the subVI will finish. (and return stuff to mainVI that i can deal with on my own)
    Here's the problems.
    1)  in the "parallel for loop" I have a flat sequence structure.. I haven't had time to incorporate some data dependency into these two sequential sections, but basically, I just care that the "inner while loop" condition is met before the data is collected and queued.  I think I can do this on my own, but if you have suggestions, I'm interested.
    2)  I can easily get the outer for and while loops to run sequentially, but I want them to run in parallel.  My reasoning for this is that that I anticipate the two tasks taking very different amounts of time. .. basically, I want the while loop to just keep polling the queue to get everything out of it (or I suppose I could somehow use notifiers - suggestions welcome)...  the thing is, this loop will probably run faster than the for loop, so just checking to see that the queue is empty will not work... I need to meet the additional condition that nothing else will be placed in the queue - and this condition is met when the for loop is complete. basically, I just can't figure out how to do this.
    3) for now, I've placed a simple stop button in the 'parallel while loop', but I must be missing something fundamental here, because the stop button is totally unresponsive.  i.e. - when I press it, it stays depressed, and nothing happens.
    suggestions are totally welcome!
    thanks,
    -Z
    Attachments:
    daq01v1.vi ‏59 KB

    I'd actually like to add a little more, since I thought about it a bit and I'm still not quite certain I understand the sequence of events...
    altenbach wrote:
    zskillz wrote:
    So i read a bit more about the 'dequeue element' function, and as I understand it, since there is no timeout wired to the dequeue element function, it will wait forever, thus the race condition I suggested above can never happen!
    Yes, you got it!
    As I've thought about it a bit more, there's a few things that surprise me... first, the reason the 'dequeue element while loop' errors is not because there's nothing in the queue, it's becaues the queue has been released and it's trying to access that released queue...   However the problem I have is this --- Even though there's no timeout wired to the dequeue element, I still would think that the while loop that contains it would continue to run at whatever pace it wanted -- and as i said before.. most of the time, it would find that there is nothing to dequeue, but once in a while, something is there.  however, it seems that this loop only runs when something has been enqueued.  the reason I say this is illustrated in the next code sample MODv2 that's attached below.  I've added a stop button to the "queue size while loop" so the program runs until that is pressed.  I've also added a simple conditional in the "dequeue while loop"  that generates a random number if it a button is pressed... but this button is totally non-responsive... which means to me that the "dequeue while loop" isn't actually continuously running, but only when an element is added to the queue.  this still seems almost like the 'dequeue while loop" waits for a notifier from the queue telling it to run.  can you explain this to me? because it is different from what I expect to be happening.
    rasputin wrote:
    I tried to open your VIs but it doesn't work. LV
    is launched, the dialog box (new, open, configure...) opens and then...
    nothing. Not even an error message. I guess it isn't a problem of LV
    version or a dialog box would appear saying this. Could you, please,
    send a image of the code?
    Thanks,
    Hi Rasputin, I'm using LV8.  I assume that was your problem, but who knows.  I've attached a pic of of altenbach's solution since it's what I needed.
    thanks
    -Z
    Message Edited by zskillz on 10-20-2006 11:49 AM
    Attachments:
    daq01v1MODv2.vi ‏63 KB
    daq01v1MODpic.JPG ‏116 KB

  • Which Mac Pro? More cores=slower speeds? And most of us know the speed matters or FPU for music and I don't understand the faster is for the least amount of procs. And while I get the whole rendering thing and why it makes sense.

    Which Mac Pro? More cores=slower speeds? And most of us know the speed matters or FPU for music and I don't understand the faster is for the least amount of procs. And while I get the whole rendering thing and why it makes sense.
    The above is what the bar says. It's been a while and wondered, maybe Apple changed the format for forums. Then got this nice big blank canvas to air my concerns. Went to school for Computer Science, BSEE, even worked at Analog Devices in Newton Massachusetts, where they make something for apple. 
    The bottom line is fast CPU = more FPU = more headroom and still can't figure out why the more cores= the slower it gets unless it's to get us in to a 6 core then come out with faster cores down the road or a newer Mac that uses the GPU. Also. Few. I'm the guy who said a few years ago Mac has an FCP that looks like iMovie on Steroids. Having said that I called the campus one day to ask them something and while I used to work for Apple, I think she thought I still did as she asked me, "HOW ARE THE 32 CORES/1DYE COMING ALONG? Not wanting to embarrass her I said fine, fine and then hung up.  Makes the most sense as I never quite got the 2,6,12 cores when for years everything from memory to CPU's have been, in sets of 2 to the 2nd power.  2,4,8,16,32,64,120,256,512, 1024, 2048,4196,8192, 72,768.  Wow. W-O-W and will be using whatever I get with Apollo Quad. 
    Peace to all and hope someone can point us in THE RIGHT DIRECTION.  THANK YOU

    Thanks for your reply via email/msg. He wrote:
    If you are interested in the actual design data for the Xeon processor, go to the Intel site and the actual CPU part numbers are:
    Xeon 4 core - E5.1620v2
    Xeon 6 core - E5.1650v2
    Xeon 8 core - E5.1680v2
    Xeon 12 core - E5.2697v2
    I read that the CPU is easy to swap out but am sure something goes wrong at a certain point - even if solderedon they make material to absorb the solder, making your work area VERY clean.
    My Question now is this, get an 8 core, then replace with 2 3.7 QUAD CHIPS, what would happen?
    I also noticed that the 8 core Mac Pro is 3.0 when in fact they do have a 3.4 8 core chip, so 2 =16? Or if correct, wouldn't you be able to replace a QUAD CHIP WITH THAT?  I;M SURE THEY ARE UO TO SOMETHING AS 1) WE HAVE SEEN NO AUDIO FPU OR PERHAPS I SHOULD CHECK OUT PC MAKERS WINDOWS machines for Sisoft Sandra "B-E-N-C-H-M-A-R-K-S" -
    SOMETHINGS UP AND AM SURE WE'LL ALL BE PLEASED, AS the mac pro      was announced Last year, barely made the December mark, then pushed to January, then February and now April.
    Would rather wait and have it done correct than released to early only to have it benchmarked in audio and found to be slower in a few areas- - - the logical part of my brain is wondering what else I would have to swap out as I am sure it would run, and fine for a while, then, poof....
    PEACE===AM SURE APPLE WILL BLOW US AWAY - they have to figure out how to increase the power for 150 watts or make the GPU work which in regard to FPU, I thought was NVIDIA?

  • When I open itunes to play content I've already purchased and while attempting to view trailers for movies in the itunes store, I receive a generic error message from windows, and I'm directed to reinstall the latest version of itunes.  Not a fix.  Help?

    When I open itunes to play content I've already purchased and while attempting to view trailers for movies in the itunes store, I receive a generic error message from windows, and I'm directed to reinstall the latest version of itunes.  Not a fix.  Help?

    after perusing other subjects with playback issues: 
    this is the fix: 
    -Launch Control Panel - Double click Quicktime, If you do not see quicktime, look on the top left side of control panel and switch to classic view. This will then allow you to see Quicktime.
    -Now click the advanced tab and click on Safe Mode GDI Only, Apply, then ok.

  • HT1766 How do i combine 2 distinctly unique backups so as to merge my notes and contacts ?  Can i simply restore both and the data will be merged, or will one complete backup merely overwrite the other ?

    How do i combine 2 distinctly unique backups so as to merge my notes and contacts ?  Can i simply restore both and the data will be merged, or will one complete backup merely overwrite the other ?

    you can't merge backups.  it's all or nothing.  one or the other.

  • Use event structure and while loop in parallel

    Hello, I would like to use an event structure in parallel with a while loop. I have a camera that needs to constantly take pictures and I have that setup in the while loop. I also however need to do other functions in conjunction with the picture taking. I have about 50 or so events that need to have access to while the pictures are taken. Is there any way to do this? If not is there any way to have a global stop variable that is attached to all 50 of the events. I know I can do this the hard way and have each boolean event in the event structure be attached to the while loop stop control. This is however very inefficient. I would also like to know if I can simply use a mouse click as the stop of the while loop. Am I able to have a variable that goes from false to true on mouse click without using the event structure to do this? Thanks.

    Yes, just place the event structure in a second while loop.
    Add a stop button to the other while loop and add an event for the stop button to stop both loops. For a simple example, see my VI posted here:
    http://forums.ni.com/ni/board/message?board.id=170&message.id=176367&jump=true
    Simply add more event cases as needed.
    LabVIEW Champion . Do more with less code and in less time .

  • Action listeners and while loops

    Hi. I have a while loop, that runs for some condition
    in this loop, i'm adding as many buttons as the condition holds.
    for each loop, i adds an action listener.
    the problem is when i want to use the action listener. it, of corse, respond to the last button in the loop. how can i make all the buttons work? i dont know ho many loops there will be, ergo i don't know how many buttons there will be...
    read from file
    while (file is not empty)
    ImageButton = new ImageIcon (name from file);
    theButton = new JButton(imageButton);
    myPanel.add(theButton);
    theButton.addActionListener(this);
    buttonId = i++;
    in the action listener
    if (listener = theButton)
    //do something

    of corse it would only respond to the last button added, thats what you told it to do. In your while loop you assign the variable "theButton" to be a new JButton. Since "theButton" in reassigned with each iteration of your loop, it will always point to the last button you created. So, in your actionListener when you check if (listener = theButton) it will only know about the last button you added. You will need to find some other way of determining which button was pressed. One possible solution would be to have a unique actionListener for each button. Another option might be to cast the source of the action to a JButton. i.e.
    public void actionPerformed(ActionEvent e)  {
         if (e.getSource() instanceof JButton) {
              //do something
    }

  • HT3964 My MacBook Pro i5 Dual Core has a hardtime waking up when the computer is put to sleep and only when it goes to sleep and has been asleep for a while. The indicator light flashes on and off for a while and then freezes. I've done an SMC reset once.

    Does any one have the same problem with their MacBook Pro i5 Intel Dual Core?  If the computer goes to sleep (not the screen) and is asleep for a while, when I try to wake it up it doesn't respond. I have to power it downn and restart it and sometimes it takes two or three attempts. Otherwise it works fine. I upgraded the memory to 8 GB. That is the only alteration doen to it. I've performed one SMC restart and now it wakes up  but it takes a while and a gray screen shows up. When I insert a DVD it won't start automatically I have to start the application in order to see it. Any suggestions?

    http://www.apple.com/support/macbookpro-videoissues/

  • How can i check my setting details are correct on my iPhone I recevied an error when sending a text this morning and while checking it out noticed my state and city are wrong

    How can i check my setting / about tab? This morning I got an error message say something wasn't safe (not sure what) I think it was my common name whcih is ch4iv.myvzw.com and while looking in there I noticed my state say NJ I live in PA, I did not buy my phone in NJ, the city says Bedminster I have never even been there. Can anyone advise?
    Can't I go on my Apple account and get to my setting / details.

    Here is the message...

  • Macbook air mid 2013, I erased my HD and while downloading the OS screen went of and when I switched back on I get a file icon with a question mark.

    I erased my HD and while downloading a new screen went of.When I switched on again there was a file icon with a question mark

    restart holding down command+r, you'll be able to reinstall your OS here

  • I tried to charge my iPod Touch 5th generation but it died while charging  and it was tuning and it said i had to connect to iTunes so i did and i had to restore it to use it and while restoring an error code (9) appered and i can't use it. Plz help

       So  I was using my iPod Touch 5th generation and the charger wouldnt charge it and it died then while it was in the process of tuening back on the apple logo dissapeered and it kept on turning on and off so i put it into DFU mode and it said to plug it into itunes to i did and it said i had to restore it to use it but when i tried to restore it it brought up ," Couldnt restore ipod, error code (9) " ..... and i have tried 3 different USB cables and two different computers and USB ports and i have no clue what to do so i would like help from anyone please that would be awesome!!!!
                        Thank you, 
                                           Zac

    Zac henderson wrote:
    ...Couldnt restore ipod, error code (9) " ...
    Try here  >  Configure security software

  • Multiple problems: can't open two windows, browser doesn't close although window disappears, and after working for a while I loose my ability to cut and paste or use drop down arrows

    Maybe two weeks ago I discovered that I could no longer open two windows at a time (I can still open multiple tabs). I am also having problems with cutting and pasting, which is crucial to my on-line job. Plus, when I exit Firefox, it doesn't always shut down, so then when you go to re-open, of course, it won't (unless you go into process and turn it off). I have re-installed multiple times and I have also used restore. Nothing seems to be fixing this and I really, really don't want to use IE, especially for work.

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")
    See also "Hang at exit":
    * http://kb.mozillazine.org/Firefox_hangs
    * [[Firefox hangs]]
    Maybe also do a malware check with a few malware scan programs.<br />
    You need to use all programs because each detects different malware.<br />
    Make sure that you update each program to get the latest version of the database before doing a scan.<br />
    * http://www.malwarebytes.org/mbam.php - Malwarebytes' Anti-Malware
    * http://www.superantispyware.com/ - SuperAntispyware
    * http://www.safer-networking.org/en/index.html - Spybot Search & Destroy
    * http://www.lavasoft.com/products/ad_aware_free.php - Ad-Aware Free
    * http://www.microsoft.com/windows/products/winfamily/defender/default.mspx - Windows Defender: Home Page
    See also "Spyware on Windows": http://kb.mozillazine.org/Popups_not_blocked and [[Searches are redirected to another site]]

  • How to incorporate adapter module while writing the adapter metadata for it

    Hi all,
             We  are developing a adapter and the custom adapter module has been prepared.Now we need to write our own adapter metadata. So I need to know in detail how to incorporate our custom adapter module into our adapter metadata.
    Paul

    hi
    check the below links
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/daa51a96-0b01-0010-738f-a0ecfd06104e
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/7086f109-aaa7-2a10-0cb5-f69bd2affd2b
    https://www.sdn.sap.com/irj/sdn/teched2004
    note:reward points if solution found helpfull.....
    regards
    chandrakanth.k

  • Firefox 5 works for a while but then won't open webpages and has to be restarted. Happened with F4 too.

    Running OSX 10.6.8 on a 2-year-old MacBook Pro. Everything will be working fine and then after a random interval of time (anywhere from 5 minutes to hours), Firefox won't connect to the internet any more and will display an error message.
    I posted a question when this happened in Firefox 4 and it was never resolved.

    You can try disabling emoticons and image previews in your IM appearance settings in your Skype options to see if that changes anything.  Some people running Windows XP have had odd graphical and resource issues with versions of Skype above 7.5.  The alternative solution would be to downgrade to Skype 7.5 for the time being.  You can find links to 7.5 in the thread below. http://community.skype.com/t5/Windows-desktop-client/Skype-7-6-crashes-on-startup/m-p/4031560/highlight/true#M353247 

  • How do I create a start/stop button for each separate while loop within my program, when each of them does a different task?

    I have a multimeter VI with separate while loops to accomplish the different tasks of reading  voltage, current, etc. Each while loop has a stop button, but I need a button that will have to be pressed in order for the while loop to even start. I tried putting another while loop around the present one, but it still has to run once before it will stop. I want the user to have to press the button before it runs, because they interfere with each other.
    I am just learning so patience and your kind assistance is greatly appreciated!
    ElectroKate

    iZACHdx wrote:
    Hello,
    I'm not entirely clear with everything you have going on and what you want your final functionality to be, but you can use sequence structures to prevent a loop from starting until the user presses a button like this:
    -Zach
    I have to ask, why is an NI employee using examples using sequence frames? The same thing could be accomplished using data flow by simply wiring the value of the first stop button out of teh first while loop and connecting it to the second loop. This would then use data flow to control the sequence. Why show new users bad programming methods?
    As to the original question I would concur with altenbach on using an event structure.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

Maybe you are looking for

  • How to find content of a constraint etc.

    Hi, select constraint_name from user_constraints where table_name = 'EMP'; shows to two constraints for the given table of EMP. Now, how to find CONTENT of each of these two constraints? Secondly, how to find if a particular column is nullable (progr

  • How to send HTML mail with images multipart/related message

    Hi, Could any body tell me how to send HTML mail with images in "multipart/related" message,if any body can give the code ,it would be helpful. Thanks

  • How to create Business partner from uploaded file by Function module?

    Hi Experts, I have uploaded Business partner data from a file to server now from individual records I have to create Business partner and have to update the records in the tables. Means from on record i have to create one business partner in sap syst

  • Disable row-marking in OO ALV

    Hello, I have an OO ALV where I can select all the rows of the list, but I want to disable the row-marking in some lines. For example, in a list with 10 rows, I want that the last 5 rows were not selectable, but the first 5 rows have to be selectable

  • Balancing field PCtr is missing in Asset PO

    Hi all of you, When I am doing Asset PO with the Account assignment category "A", system is not deriving the Cost center - > Profit center through the given asset master number. And the system is not allowing me to enter the cost center / profit cent