aspose file tools*
The moose likes Beginning Java and the fly likes  Number Addition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " Number Addition" Watch " Number Addition" New topic
Author

Number Addition

jason tourne
Greenhorn

Joined: Apr 01, 2011
Posts: 10
I am trying to add two ints taken from JOptionPane inputs and output the result in another JOptionPane. What I have so far is below, but I don't know what to put in the spaces provided.


___firstAmount = JOptionPane.___("First amount?");

int firstNumber = Integer.___(firstAmount);

____ secondAmount = JOptionPane.___("Second amount?");

int secondNumber = Integer.____(secondAmount);
int total = firstNumber + secondNumber;
___.___(null, ""___ ___);
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

jason tourne wrote:I need help...

Could you be more specific?
jason tourne
Greenhorn

Joined: Apr 01, 2011
Posts: 10
the blank spaces that are in the code is what I need help filling out.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4461
    
    8

jason tourne wrote:the blank spaces that are in the code is what I need help filling out.

We don't really just hand out homework answers at JavaRanch. This place is all about helping you learn, and you don't learn if somebody else does it for you.

So, how far have you got with it by yourself?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

So check out the Javadocs. I'll give you a few hints.
___firstAmount = JOptionPane.___("First amount?");

The obvious place to start is JOptionPane. Go to the method list and find a static method (because it's called without an instance) that takes one String (or Object) and returns... something.
int firstNumber = Integer.___(firstAmount);

Take that something and check out java.lang.Integer to find a static method that turns this something into an int.
____ secondAmount = JOptionPane.___("Second amount?");
int secondNumber = Integer.____(secondAmount);

You should be able to fill in these gaps now as well.
int total = firstNumber + secondNumber;
___.___(null, ""___ ___);

This one is a bit trickier, but here's my guess - the first gap is JOptionPane. That's because that's part of your requirements - output using JOptionPane. There is no "new" keyword here so it's going to be another static method. It takes two arguments. The first can be anything. The second is something that is returned by "" X Y. I'll let you puzzle this out for yourself, but think about your requirements - output the result.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jason tourne
Greenhorn

Joined: Apr 01, 2011
Posts: 10
jason tourne wrote:I am trying to add two ints taken from JOptionPane inputs and output the result in another JOptionPane. What I have so far is below, but I don't know what to put in the spaces provided.


JOptionPane firstAmount = JOptionPane.___("First amount?");

int firstNumber = Integer.___(firstAmount);

____ secondAmount = JOptionPane.___("Second amount?");

int secondNumber = Integer.parseInt(secondAmount);
int total = firstNumber + secondNumber;
___.___(null, ""___ ___);



I put JOptionPane on the first underline and then I got parseInt for another underline word, but I need help.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4461
    
    8

The first line is getting an input value from the user and assigning it to a variable. It's unlikely that the user will be inputting a JOptionPane, so you may want to rethink your first blank.

Did you look at the Javadocs for JOptionPane (the forum software helpfully adds a link to them)? As Rob told you, you're looking for a static method in that class that returns something useful.

parseInt looks good. And remember you've got two input values to convert.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

You already found parseInt, and you know the parameter type. That means your options for the gap before "secondAmount" is already limited to the parameter type or any super type.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40

Please QuoteYourSources


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Number Addition