• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create this simple program in Java?  RSS feed

 
mark jenins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Hope that you could help me regarding this. I am just new in Java and i would like to know and understand how to create this:

text version of the design:

n1 operator n2 answer

10 * 5=50
4- 3=1
N?Operator? N?=ans
N?Operator? N?=ans
N?Operator? N?=ans
N?Operator? N?=ans
N?Operator? N?=ans
N?Operator? N?=ans
N?Operator? N?=ans
N?Operator? N?=ans

CALCULATE


These are the simple requirements:

1.User will enter numbers in n1 and n2
2.User is able to choose operator for all 10 rows. The user will just simply input the chosen operator on the "operator" column. (*,/,-,+,%)
3.calculate button will display the answer of the 10 fields on the leftmost part of the grid. The one on the "answer" column.
4. I will gladly appreaciate and be thankful if someone could help me create a dos base or console base output of the said program and window based or swing based of the program.

thank you java ranch.

[ October 16, 2008: Message edited by: mark jenins ]
[ October 17, 2008: Message edited by: mark jenins ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. One of the philosophies of this place is that we help those who show some effort on their own behalf. So start writing your program, when you get stuck come back and ask some specific questions, some one will be glad to help you.
 
mark jenins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for now, this is what i got ...

public class TenNumbers {

public static void main (String args[]){

System.out.println("n1 operator n2 answer");
System.out.println("CALCULATE");
}
}

i guess i will be needing a grid and 10 set of system.out for the 10 inputs.
 
mark jenins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i add the two values and then let the user choose an operator based on my code? thanks guys.
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nvm
[ October 17, 2008: Message edited by: Piet Verdriet ]
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just another cross poster.
http://forums.sun.com/thread.jspa?threadID=5340607
 
mark jenins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This code is the progress with my simple program. I am just having problem with the output of the buttons, whenever i click the operators of the second set of computation the answer on the first set will be erased.

what i mean is that the answer from the first (n1 + - * % / n2 answer) will be erased if i will click the button of the next (n1 + - * % / n2 answer). I think, there is a problem with my ActionPerformed. they share the same displayResult(result) method for the output of the if-else. Please some one help me. I did not post the APIs that I used because it is already understandable that those APIs will only show a messagebpx and convert a float to string for the display of the output on the (outputOfTheOperand2 and outputOfTheOperand). thanks.

 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke is right; you ought to tell us (and the people on the other forum) if you post on several sites. But I couldn't find the thread quoted on the other forum.

You have changed the size of your posts drastically; you needn't expect anybody to read all that lot. But at a quick look, you are using a single actionPerformed method. You can see how awkward that will be if you use several buttons; I look on that as not object-oriented programming at all.
Your setBounds calls suggest you are not using the LayoutManager properly.

I would suggest you go back to telling us what progress you have made with a command-line based version of the application. That will allow you to isolate the program logic from the display, and everybody can see what is happening.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!