Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 01-25-2004, 10:50 PM   #1
Member (8 bit)
 
Join Date: Nov 2001
Location: Philly
Posts: 189
Help me with JAVA

Hi, I have a java program I have to write for school. I am having some problems. I have to create a calculator (like the windows one) with the add, subtract, mult, and divide functions.

Here is the wording:
Minimum requirement: addition, subtraction, and multiplication of two single digit numbers should be implemented. Usage: first, use mouse to select the first number; secondly, select an operator, then select the second number (in order, rather than pre-order, nor post-order). Press the “=“ button and display the result in a JTextField.

Here's what I have so far but it is not working (im doing it in JBuilder but this file is text so all can view).

ANY ANY ANY help would be appreciated. Im just going for functionality now, I'll try to make it look "pretty" later.

FILE: CLICK

Thanks!
pzs22 is offline   Reply With Quote
Old 01-29-2004, 09:30 AM   #2
sym
Member (7 bit)
 
Join Date: Nov 2001
Location: Rochester, NY
Posts: 87
I've just looked at it briefly, but I think you may want to look at the following:

//Once a button is pressed, the following code takes care of the display
public void actionPerformed(ActionEvent click)
{
char key = click.getActionCommand().charAt(0);
updateScreen.send(updateScreen.retrieve()+key);
}


I see that you have a class "Operations" to handle the actual calculations, but I don't see where you actually call it. It appears that the code just continually adds chars to the text display. If this is correct, you may want to try something like this:


//Once a button is pressed, the following code takes care of the display
public void actionPerformed(ActionEvent click)
{
char key = click.getActionCommand().charAt(0);
if (key == '=' || updateScreen.retrieve.length >= 3)
{
Operations op = new Operations(.......)
op.Solve()
} else {
updateScreen.send(updateScreen.retrieve()+key);
}

}


You would also need to put code in the Operations constructor to retrieve the 2 values and the operation sign from the main text display.

I haven't actually compiled or run this, so it is only a visual inspection. Sorry if I'm too far off base.
sym is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:46 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2