• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem with FOR loop..Need Help ASAP...

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've this class assignment that says:

Design and write an ArithmeticGUI class that allows users to input play with numbers multiplication. The GUI should contain three JTextField, one for input first number, second for second number and third for the result of multiplication of both numbers. There should be one button which the user can signal that correct multiplication result has been entered. The multiplication table of the second number should be displayed in the text area and the correctness of the multiplication result should also be displayed in a text field, but this should be set uneditable. A sample Arithmetic GUI interface is displayed below:

If users input a correct multiplication result of two numbers, the below should happened:



If users input a wrong multiplication result of two numbers, the below should happened:




i've already try it but i have problem at the for loop structure...
here the java code that i try..





please help me solve this...
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/UseAMeaningfulSubjectLine
http://faq.javaranch.com/java/UseCodeTags
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you really doing is a times table. Then the Times assignment of the Cattle Drive may be some help.

If you figure out the algorithm for that, you should have solve your original problem.
 
Marshal
Posts: 80617
468
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use the code button; it makes your code much easier to read.

You are right about having problems with for loops; I suggest you find a book and read up about for loops, or find the syntax in the Java Tutorials.

Anmd welcome to JavaRanch
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

for (num1 * num2 == result) //(have problem)


I'm not sure what you are trying to do here. What you have in your parens: "num1 * num2 == result" is essentially a boolean. it's either 'true' or 'false'.

A 'for' statement doesn't take a boolean - it takes three things for setting up, testing, and updating variables. Then, the code inside the curly brackets potentially runs multiple times.

So really, the question is, what are you trying to DO there? Are you trying to test something? i don't think so, because it's a repeat of what's in your if statement just above it.

I assume you are trying to loop around and print out all those products.

So, as others have said, look in a book or online tutorial for how to set up a for-loop. Then, see if you can write one that does nothing more that prints "hello" 12 times. Then get it to print something like:

1
2
3
4
5
6
7
8
9
10
11
12

etc, and add a little bit each time.
 
ELL TIM
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:

for (num1 * num2 == result) //(have problem)


I'm not sure what you are trying to do here. What you have in your parens: "num1 * num2 == result" is essentially a boolean. it's either 'true' or 'false'.

A 'for' statement doesn't take a boolean - it takes three things for setting up, testing, and updating variables. Then, the code inside the curly brackets potentially runs multiple times.

So really, the question is, what are you trying to DO there? Are you trying to test something? i don't think so, because it's a repeat of what's in your if statement just above it.

I assume you are trying to loop around and print out all those products.

So, as others have said, look in a book or online tutorial for how to set up a for-loop. Then, see if you can write one that does nothing more that prints "hello" 12 times. Then get it to print something like:

1
2
3
4
5
6
7
8
9
10
11
12

etc, and add a little bit each time.




Sorry bout the code,i'm new to this site..also new to java programming...the thing is i want the output to print out like this when user key in the second number,then the multiplication are base on the second number.

1 x 2 = 2
2 x 2 = 4
3 x 2 = 6
4 x 2 = 8
...
...
...
12 x 2 = 24

i try using this code but still cant get what i want..

 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one of the hardest things to learn as a new programmer is to not try and do too much at once. The less you try and accomplish on each build/debug/test cycle, the easier it is to find your problems.

So, I'd suggest this:

try and write code that when the user enters their second number, you get it to print the number 1-12, each on a new line. Get that to work. ONLY after you are sure that is working perfectly, try and change it to print

1 x <the input second number>
2 x <the input second number>
... etc

ONLY after you have that working, try and get it to print the actual product on the end.

 
Campbell Ritchie
Marshal
Posts: 80617
468
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ELL TIM wrote:..also new to java programming...

Has whoever is teaching you not taught you about the structure of a for loop?
 
ELL TIM
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just figured it out actually. Thanks for the tips! (^_^)
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(OT) Mostly I was just entertained that we got to say "buttCheck".
 
reply
    Bookmark Topic Watch Topic
  • New Topic