kanaka tam

Ranch Hand
+ Follow
since Jan 19, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kanaka tam

Hello folks,
The application below is supposed to catch four kinds of exceptions and i have tried my best with a little help from a fellow memeber but not very successful in catching all of the exceptions. I am very exhausted and I can't figure out what is that I am doing wrong? If anyone could help me i would greatly appreciate that.


thanks,
kt
[ August 01, 2005: Message edited by: kanaka tam ]
18 years ago

Originally posted by Ernest Friedman-Hill:
For some reason, continued with a slightly reworded repost here.



Sorry about that, didn't mean to do that on purpose. Totally forgot about posting i did yesterday from school and posted it again. Anyway, i have completed 75% of the problem.
My code handles the follwing exceptions.
When the user fails to enter any value and presses calculate, A message "Enter an Expression" appears in the input text field. if the user enters say "12 - a" i display a message invalid operand.
But my code does not catch an exception like say "12 & 2" then i should display invalid operator and also a message wrong number of elements if the user enters "12 - ". Any help would be greatly appreciated.
Thank you,
kt
18 years ago
Hi folks,
I have written an application that acts like a simple calculator and performs addition or subtraction of numbers entered in a certain pattern. I was successful in writing the program and compiling it and exceuting it. I am having little bit of trouble in handling exceptions.
I have to handle four kinds of errors and i did get 1 and 3. But didnt know how to achieve 2 and 4.
1. No input at all. The user presses �calculate� and the input text field has nothing to calculate. Put the message, �Enter An Expression� in the top text field if this occurs (and make the bottom text field blank.
2. Wrong number of operators and operands. There should always be an odd number of items (�55� is one instance, � 3 + 2� is three, etc.) Report �Wrong Number Of Elements� in the bottom text field if there is not an odd number of elements (after you tokenize on �+� and �-� ).
3. Invalid operand. If you find something that is not a valid operand (i.e., not an integer) in a place where you would expect an operand to be, then leave the user�s expression in the top text field and put the message �Invalid Operand Or Operator� in the bottom text field.
4. Invalid operator. If you find something that is not a valid operator (i.e., not a �+� or a �-�) in a place where you would expect to find an operator, then leave the user�s expression in the top text field and put the message �Invalid Operand Or Operator� in the bottom text field.
Below is my code:

My code handles the follwing exceptions.
When the user fails to enter any value and presses calculate, A message "Enter an Expression" appears in the input text field. if the user enters say "12 - a" i display a message invalid operand.
But my code does not catch an exception like say "12 & 2" then i should display invalid operator and also a message wrong number of elements if the user enters "12 - ". Any help would be greatly appreciated.
Thank you,
kt
[ July 30, 2005: Message edited by: kanaka tam ]
18 years ago
Hi folks,
I have written an application that acts like a simple calculator and performs addition or subtraction of numbers entered in a certain pattern. I was successful in writing the program and compiling it and exceuting it. I am having little bit of trouble in handling exceptions.
I have to handle four kinds of errors and i did get two of them. But didnt know how to achieve the other two.
1. No input at all. The user presses �calculate� and the input text field has nothing to calculate. Put the message, �Enter An Expression� in the top text field if this occurs (and make the bottom text field blank.
2. Wrong number of operators and operands. There should always be an odd number of items (�55� is one instance, � 3 + 2� is three, etc.) Report �Wrong Number Of Elements� in the bottom text field if there is not an odd number of elements (after you tokenize on �+� and �-� ).
3. Invalid operand. If you find something that is not a valid operand (i.e., not an integer) in a place where you would expect an operand to be, then leave the user�s expression in the top text field and put the message �Invalid Operand Or Operator� in the bottom text field.
D. Invalid operator. If you find something that is not a valid operator (i.e., not a �+� or a �-�) in a place where you would expect to find an operator, then leave the user�s expression in the top text field and put the message �Invalid Operand Or Operator� in the bottom text field.
Below is my code:


Thank you,
kt

[ July 29, 2005: Message edited by: kanaka tam ]
[ July 29, 2005: Message edited by: kanaka tam ]
18 years ago
Hello Folks,
I have written an application that manages the x and y position of a String object through two seperate JSlider objects. The Display Area for the String object is a subclass of the JPanel class. The content of the String object is updated through a JButton and JTextField objects. I was successful in writing the code up until where i could get the String from TextField and move it around using the Horizontal and vertical sliders. My problem here is as i move the sliders to it maximum value the string disappears out of the drawing area which according to my program should not disappear from the drawing area. Are there any methods that would keep the String from not disappearing the drawing area. Below is my code: It is very lengthy. My code compiles fine and executes too except for the above problem.




Thank you,
kt
[ July 24, 2005: Message edited by: kanaka tam ]
18 years ago

Originally posted by John Smith:
The third and fourth arguments in Rectangle2D.Double() are width and height, respectively. With that in mind, to show the bars horizontally, your code would look something like this:



Thanks, John. I appreciate your help. I got the bar chart the way I wanted. I couldn't have come this far without the help of this forum and help from folks like you and others.
kt
18 years ago

Originally posted by John Smith:


I ran your code, and it displays the bars vertically, as you want. Are you sure that's the code that you are actually running?



I am extremely sorry. I wanted it to display horizontally instead of it being displayed vertically. Sorry!! you are so kind to run the code. Yeah i wanted it to be displayed horizontally.
18 years ago

Originally posted by John Smith:
Because of the integer division, your degreeIncrement variable will always be equal to zero. Subsequently, the arcs you are trying to draw all have angle 0 and that's why you don't see them. The fix is to divide by a float and cast the result to an integer.

Additionally, the line startAngle += degreeIncrement; should be inside the for loop.



John,
I had to draw an equivalent bar chart with the same numbers which i did and got the output as well. One little problem is that i need to display the bar vertically. Right now i have got it to display horizontally. I did play with the x and y coordinates but not able to make it display vertically.
Help appreciated,
Thanks,
kt. Here is my complete code
18 years ago

Originally posted by John Smith:
Because of the integer division, your degreeIncrement variable will always be equal to zero. Subsequently, the arcs you are trying to draw all have angle 0 and that's why you don't see them. The fix is to divide by a float and cast the result to an integer.

Additionally, the line startAngle += degreeIncrement; should be inside the for loop.



Thanks John. I appreciate you taking time to answer my question. As always, I am very greatful to this forum and great folks like you and others for helping me out.
kt
18 years ago
Hello folks,
I am trying to write a program that plots a pie chart for five input numbers. Below is my code. I have no compilation errors but i don't see any picture in the screen after excetion. Any help greatly appreciated. I am a beginner trying to learn Java and i tend to make silly mistakes, didn't know what i did this time cause i am not getting any compilation errors.
thank you,
kt


[ July 09, 2005: Message edited by: kanaka tam ]
18 years ago

Originally posted by Timmy Marks:
Sorry if I wasn't clear, the grow field and the radius should be members of the individual classes, and the changeSize() method is a method of the Shape class, overridden in the subclasses. Actually, the name radius is maybe misleading, since it is more associated with circles, and not with squares.

Since they are both growing at the same time, start one of them with grow = true and the other with grow = false!



Thanx Marks. I kind of figured that out and fixed it. As always i am so greatful to this forum for helping me to do java programming which when i started made me feel very scared.
Kanaka
18 years ago

Originally posted by Timmy Marks:
Actually, only one (or none) of the two operations grow() or shrink() actually changes anything (What happens if size == 50?). Maybe a single method would be better: a boolean saying whether it grows or shrinks



P.S. Would someone edit the original post to fix the code tags??? On my monitor it's like 200 inches wide!

[ June 14, 2005: Message edited by: Timmy Marks ]



Marks,
Thank you. I appreciate your help. But the problem is different, actually when change button is pressed, circle should grow by 10 pixels and square should shrink by 10 pixels and when they both become too small or too large then they reverse that is circle shrinks and square grows.
Right now both grows at the same time and shrinks at the same time. As you can see that i am a novice, I am going nuts over this.ou and Ernest have been very helpful and trust me i am trying hard to get the sloution. Any help greatly appreciated.
Kanaka
18 years ago

Originally posted by Ernest Friedman-Hill:
That looks great -- except that you're calling both grow() and shrink() on each shape, so that the net effect is... nothing! You want to just grow the circle, and shrink the square, right?


Ernest,
Thank you for you reply. But the problem is
Each time the button is pressed, the circle should grow by 10 pixels and the square shrink by 10 pixels. Whenever a shape gets too small (less than or equal to 20 pixels across) or too big (greater than or equal to 100 pixels across) it reverses its growth pattern (i.e., if it was shrinking, it now grows, or vice versa.)
This is where i have problem and so that's why i called shrink and grow methods on both of them.
I tried doing it with just
myCircle.grow();
mySquare.shrink(); in the action performed. I am not able to see any change. I am very surprised that nothing happened to the shapes.
could you please identify what am i doing wrong?
Kanaka
18 years ago

Originally posted by Ernest Friedman-Hill:
Here's what I would do:

1) Give Shape a shrink(int pixels) method and a grow(int pixels) method. These methods have to change the member variable that controls the size of the shape.
2) In actionPerformed(), call the appropriate methods on the appropriate objects, then call repaint().



Please forgive me if i have done this without understanding what you meant .Right now i have put this code inside shape class


then inside action performed i called these methods on circle and square shapes respectively.

It still doesn't work as expected. In the sense, i have a change button and a square and a circle that doesn't change. Please don't mistake me, i am trying harder and couldn't get it.
Any help appreciated,
Kanaka
18 years ago
This is a problem that i am working on is based on inheritance concept. I am having trouble in the action performed portion of the code. The problem is to create an applet that has a button (JButton) labeled �Change�, a red circle and a green square (each 50 pixels across). Each time the button is pressed, the circle grows by 10 pixels and the square shrinks by 10 pixels. Whenever a shape gets too small (less than or equal to 20 pixels across) or too big (greater than or equal to 100 pixels across) it reverses its growth pattern (i.e., if it was shrinking, it now grows, or vice versa.)Define a �super� class called Shapes for the common items shared by both the Circle and Square �sub-classes�.
I was successful in using the inheritance concept and create the code. But onlky the action performed code is where i am stuck.
18 years ago