hi,i'm new to this forum and i just started learning about java.also i have very nasty task at school to write a code for this: Exercise1:
Create class Calculator with the following variables:
intNumbers (int) names (String) x, y (float) - this variables should be private
The class should have constructor which has 2 parameters and sets the values for x and y with this parameters. Create access methods (get and set methods) for x and y.
The class should have 3 methods:
- "calculate" is class method with 2 parameters: intNumbers (int) and operator(char). This method should check the operator value (it could be +, -, or *), perform the appropriate operation (for example, if operator='+', calculate the sum of all 30 elements of intNumbers) and return the result.
- "generate" is class method with 1 parameter: intNumbers and it should store random values in the 30 elements of intNumbers.
- "longestWord" is instance method with 1 parameter: names (String) and it should calculate the longest word in the "names" array and return string with the following message: for example: The longest word is intersoft with 9 letters
Create main method and create object of this class using the constructor. Enter some values for "names" array. Give some values to x and y and print that values to the screen. Call "generate","calculate" and "longestWord" methods. IF SOMEONE CAN GIVE ME A HINT HOW TO PERFORM THIS I'LL BE VERY GRATEFULL,THANKS
Hi, welcome to the ranch! You'll find we don't do homework for folks here, but we will happily guide you along the way to do it yourself.
Try this: Find the smallest possible part of this program that you could write and prove that it works. Write the fewest possible lines of code to solve that part and no more. Once that is working, add the next smallest possible bit.
Since you're new to this, I'll give a stronger hint on a first step. Copy this little program and make it work with your own Calculator:
Give it a try. If you get stuck, show us your code and we'll figure out just how to help you. Have fun! [ October 30, 2006: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Alan B Smith
Joined: Oct 30, 2006
Thank you very much for replaing but i don't think that the solution that you've sent to me works,because i tried it and it shows that has errors.thanks anyway.