• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HELP

 
Alan B Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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[30])
names (String[5])
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[1]). 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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Alan B Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alan Smith:
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.


Stan didn't give you a solution, he gave you a starting point (in this case, a testing program to start your program). You still have to do the Calculator class yourself.

Henry
 
Alan B Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i get it,thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic