[nbusers] Re: For Loop, Array, TextArea

  • From: "Bayless Kirtley" < >
  • To: < >
  • Subject: [nbusers] Re: For Loop, Array, TextArea
  • Date: Mon, 15 Oct 2012 09:34:38 -0500
  • Authentication-results: cox.net; none
  • Importance: Normal

The error you show:
   symbol:   method setText(java.lang.String)
   location: class javax.swing.JPanel"
indicates that you are trying to setText to a JPanel instead of your JTextArea.
That is your problem.

As for your second question. Yes, use a for loop with the varying exponent as the control variable.
Also, check the Javadoc for the JTextArea methods. Your instructor suggested string concatenation
as a way to create the output but there are other ways too.

Bayless



-----Original Message----- From: coderkid
Sent: Sunday, October 14, 2012 4:03 PM
To: 

Subject: [nbusers] For Loop, Array, TextArea

I have an assignment:

Create an application that displays a listing of powers.

Input to the application is to include numbers to represent the following:

base
exponent (between 1 and 10)
Output is to list the number that you entered as a base and find the powers for that base from 1 up to the ending exponent number that is input.

Example

If a user enters a base = 3 and an exponent = 4, your program should be able to use a loop to calculate powers as follows:

31 = 3

32 = 9

33 = 27

34 = 81

Tips

Use a statement similar to the following to find the powers for the numbers that the user inputs.

power=Math.pow(baseIn, exponentIn);
NOTE – You should use a TextArea box for the output. When you use the setText command, make sure you use the jTextArea and not the jScollPane method.

To create an output message, use the concatenate (+) operator and the new line escape sequence (\n) to join together the message generated during an iteration of the loop to the message that was generated from the previous iteration of the loop.


SO, my first problem is that I do not know how to set text on the text area. I have tried but it says "cannot find symbol
 symbol:   method setText(java.lang.String)
 location: class javax.swing.JPanel"

Here is the code I used for it:

public void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {
     //when calculateButton is pressed, the following action occurs
double userBaseInputNumber = Double.valueOf(userBaseInputField.getText());
int exponentNumber ;
int userExponentInputNumber = Integer.valueOf(userExponentInputField.getText());
double finalpower=Math.pow(userBaseInputNumber, userExponentInputNumber);

String lastOutputPower= userBaseInputNumber+"to the exponent"+userExponentInputNumber+"equals"+finalpower;
answerOutputArea.setText(lastOutputPower);
   }

The code: answerOuputArea.setText(lastOutputPower); does not work, but it works if I use a text field in place of the text area. However, we have to use a text area, so I need to figure out why it is not working.


Now, I am not sure how to do the rest of the assignment. In terms of finding all of the powers of base "userBaseInput" from 1 to "userExponentInput", will I need an array or a for loop? What should it look like? So confused :x

Thanks






-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.2740 / Virus Database: 2601/5831 - Release Date: 10/14/12


[nbusers] For Loop, Array, TextArea

coderkid 10/14/2012

[nbusers] Re: For Loop, Array, TextArea

Edson Richter 10/15/2012

[nbusers] For Loop, Array, TextArea

coderkid 10/15/2012

[nbusers] Re: For Loop, Array, TextArea

Edson Richter 10/15/2012

[nbusers] For Loop, Array, TextArea

coderkid 10/15/2012

[nbusers] Re: For Loop, Array, TextArea

Edson Richter 10/15/2012

[nbusers] Re: For Loop, Array, TextArea

Bayless Kirtley 10/15/2012

[nbusers] For Loop, Array, TextArea

coderkid 10/16/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close