Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Miscellaneous > Archive > Off-Topic-Archive > Java Help
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!

bottom of page
  
Author
Thread    < Last Thread     Next Thread > Post New Thread     Post A Reply
devilmunchkin is offline devilmunchkin
Warlord
first circle of the inferno
Jul 2001
time: 05:31
  Old Post 05-10-2003 22:40
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
Java Help Support Apolyton buy from Amazon

Help!
My boyfriend has been trying to figure out this program for his java class for over a week..to no avail. The teacher won't help him and he's at his wits end. I think it's supposed to be a calculator program. He says he's having trouble getting the operator character to read into the program. Can any of you figure this out? Here's what he has for his program so far:
quote:

import java.util.StringTokenizer;

import java.text.DecimalFormat;

import javax.swing.JOptionPane;

import java.io.*;


public class Calculator

{

public static void main(String [] arg) throws IOException


{

BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));


StringTokenizer tokenizer;

int results, results2, results3, results4, num1, num2/*, operator*/, test;

String operator;//, num1, num2;

String pane1, pane2;


pane1 = JOptionPane.showInputDialog("The purpose of this program is to mimic a calculator."
+ "\n\n\nPlease enter the data in this format | 1 + 2 | .");



tokenizer = new StringTokenizer (pane1);

num1 = Integer.parseInt(tokenizer.nextToken());

operator = tokenizer.nextToken();

num2 = Integer.parseInt(tokenizer.nextToken());

test = (char) '+';

results = (num1 + num2);

results2 = (num1 - num2);

results3 = (num1 * num2);

results4 = (num1 / num2);



if (operator = test )
JOptionPane.showMessageDialog(null, "Your results are " + results + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
/*
else if (test == '-')
JOptionPane.showMessageDialog(null, "Your results are " + results2 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);

else if (test == '*')
JOptionPane.showMessageDialog(null, "Your results are " + results3 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);

else if (test == '/')
JOptionPane.showMessageDialog(null, "Your results are " + results4 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);



switch (operator)
{
case '+' : JOptionPane.showMessageDialog(null, "Your results are " + results + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);

}

*/






System.exit(0);

}





}

Asher is offline Asher
King
Calgary, Alberta
Nov 1999
time: 22:31
  Old Post 05-10-2003 23:07 Visit Asher's homepage!
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Support Apolyton

Try this

code:
import java.util.StringTokenizer; import java.text.DecimalFormat; import javax.swing.JOptionPane; import java.io.*; public class Calculator { public static void main(String [] arg) throws IOException { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenizer; int results, results2, results3, results4, num1, num2/*, operator*/, test; String operator;//, num1, num2; String pane1, pane2; pane1 = JOptionPane.showInputDialog("The purpose of this program is to mimic a calculator." + "\n\n\nPlease enter the data in this format | 1 + 2 | ."); tokenizer = new StringTokenizer (pane1); num1 = Integer.parseInt(tokenizer.nextToken()); operator = tokenizer.nextToken(); num2 = Integer.parseInt(tokenizer.nextToken()); //test = (char) '+'; results = (num1 + num2); results2 = (num1 - num2); results3 = (num1 * num2); results4 = (num1 / num2); if (operator.equals("+") ) JOptionPane.showMessageDialog(null, "Your results are " + results + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE); /* else if (operator.equals("-")) JOptionPane.showMessageDialog(null, "Your results are " + results2 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE); else if (operator.equals("*")) JOptionPane.showMessageDialog(null, "Your results are " + results3 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE); else if (operator.equals("/")) JOptionPane.showMessageDialog(null, "Your results are " + results4 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE); */ System.exit(0); } }

Jack_www is offline Jack_www
King

Donate to the Red Cross
Southern California
Jul 2001
time: 21:31
  Old Post 05-10-2003 23:11
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Support Apolyton buy from Amazon

Was he suppost to write a program that acts like a caculator. I had to do the same thing in my java intro class. Asher program is a better way going about it.

devilmunchkin is offline devilmunchkin
Warlord
first circle of the inferno
Jul 2001
time: 05:31
  Old Post 06-10-2003 03:16
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Tired of ads?

asher: thank you thank you thank you!

SlowwHand is offline SlowwHand
King
of The Cooler
Sep 1999
time: 23:31
  Old Post 06-10-2003 03:19 Visit SlowwHand's homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Remove this text

And they said Asher wasn't a gawd. HA!

Ted Striker is offline Ted Striker
Emperor
United States of America
Jan 1970
time: 21:31
  Old Post 06-10-2003 03:23 Visit Ted Striker's homepage!
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

See Asher knows all that open source crap too

Asher is offline Asher
King
Calgary, Alberta
Nov 1999
time: 22:31
  Old Post 06-10-2003 03:25 Visit Asher's homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Browse Apolyton AD-FREE

The guy who made Java is an alumnus of my uni, we were forced at gunpoint to use Java in our first year due to an abundance of Sun equipment and software.

dm: no problem.

Tell him he should catch that IOException he throws if he wants full marks.

Asher is offline Asher
King
Calgary, Alberta
Nov 1999
time: 22:31
  Old Post 06-10-2003 03:30 Visit Asher's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

I'm also confused why he needs a BufferedReader and stuff, too.

Asher is offline Asher
King
Calgary, Alberta
Nov 1999
time: 22:31
  Old Post 06-10-2003 03:49 Visit Asher's homepage!
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Support Apolyton, buy Civilization 2

Because I'm anal and bored at work: a clean version of that program.

code:
import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Calculator { public static void main(String[] arg) { StringTokenizer tokenizer; int num1, num2, result; String operator, pane1, pane2; pane1 = JOptionPane.showInputDialog("The purpose of this program is to mimic a calculator." + "\n\n\nPlease enter the data in this format | 1 + 2 | ."); tokenizer = new StringTokenizer(pane1); num1 = Integer.parseInt(tokenizer.nextToken()); operator = tokenizer.nextToken(); num2 = Integer.parseInt(tokenizer.nextToken()); if (operator.equals("+")) result = num1 + num2; else if (operator.equals("-")) result = num1 - num2; else if (operator.equals("*")) result = num1 * num2; else result = num1 / num2; JOptionPane.showMessageDialog(null, "Your results are " + result + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }

Last edited by Asher on 06-10-2003 at 03:57

Kuciwalker is offline Kuciwalker
Emperor
of Schmooism
Feb 2001
time: 00:31
  Old Post 06-10-2003 03:55
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Support Apolyton, buy GURPS/ Alpha Centauri

quote:
Originally posted by Asher
I'm also confused why he needs a BufferedReader and stuff, too.


Because using the stupid popup windows as input boxes is gay?

Asher is offline Asher
King
Calgary, Alberta
Nov 1999
time: 22:31
  Old Post 06-10-2003 03:56 Visit Asher's homepage!
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Help yourself to an AD-FREE life

But popup windows and input boxes don't need a buffered reader, nor do they throw IOExceptions.

Kuciwalker is offline Kuciwalker
Emperor
of Schmooism
Feb 2001
time: 00:31
  Old Post 06-10-2003 03:59
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Remove this text

So?

It looks a lot prettier if you do input from the console.

Plus, the chances of it throwing an IOException is nil, unless you've got something seriously wrong anyways.

Asher is offline Asher
King
Calgary, Alberta
Nov 1999
time: 22:31
  Old Post 06-10-2003 04:06 Visit Asher's homepage!
Edit/Delete Message Reply w/Quote
#13 Report this post to a moderator
Support Apolyton, buy Civilization 2

The point was he didn't need a buffered reader or an IOException since he wasn't using console input.

Kuciwalker is offline Kuciwalker
Emperor
of Schmooism
Feb 2001
time: 00:31
  Old Post 06-10-2003 04:10
Edit/Delete Message Reply w/Quote
#14 Report this post to a moderator
Remove this text

Yes he was. Wasn't he?

EDIT: n/m, you're right.

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:31.
Apolyton Time is 00:31.
    top of page
Rate This Thread:
archivepost
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0552 seconds (90.41% PHP - 9.59% MySQL) with 31 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net