954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Program Output Display Tweak Help

I have attached 2 java files which, when run, simulate a calculator that performs addition and multiplication only. I have been working on it for some time...getting assistance from varioius sources. I am having two issues I need help in correcting. They are as follows:

1) When multiplying two single digit numbers...a leading zero is attached
to the bottom digit (num2) I wish to remedy this by either removing it
for single digits or add a zero to the top digit (num1). I'm referring
to the output display.

2) When the output is displayed...the top number (num1) is shifted to
much to the right. I would like for it to be a bit more uniform.


I am trying to learn JAVA and this is my first attempt at a program other than the example from "JAVA for Dummies!" lol. Thanks in advance.

Attachments InteractiveCalculator.java (5.18KB) BigInt.java (8.54KB)
CoolHandLuke
Newbie Poster
4 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

You'll have to explain the 1st question a little more.

One the second question, if you are using a JTextField to display data, you can set the horizontal alignment.

textField.setHorizontalAlignment(JTextField.CENTER);
                                                    or   .RIGHT
                                                    or   .LEFT
                                                    or   .LEADING
                                                    or   .TRAILING
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

Can you enhance your program with adding and subtracting method as well? I'd love to see the complete calculator if you dont mind. The program occurs because of your display method. You'll need to add some code to check if the preceeding number is 0, it has to be gotten rid of before being printed out to the screen.

compiler
Newbie Poster
3 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

To server_crash, you will understand the first question if you try to run the program with some trial input. About the second question, I dont think your answer is helpful at all.

compiler
Newbie Poster
3 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 
To server_crash, you will understand the first question if you try to run the program with some trial input. About the second question, I dont think your answer is helpful at all.

I don't have time to run everyone's code. If you do, that's great. About your second comment, I just now looked at the code and saw that he's using the command line to run this.d

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

hi compiler

I have changed your code at a couple of places.
try running your code and tell me is this what was in your mind?

regards
Srinivas

Attachments BigInt.java (8.54KB) InteractiveCalculator.java (5.21KB)
cheenu78
Light Poster
45 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

You succeed in get rid of the leading Zero in the output. That's great. But what I am trying to do is come up with a better algorithm for the muliplication method. When I entered a 10 digit number times another 8 digit number, it would take like forever to get the answer. There's a huge Big O for the efficiency of this program.

compiler
Newbie Poster
3 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You