GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes HELP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HELP" Watch "HELP" New topic
Author

HELP

Alan B Smith
Greenhorn

Joined: Oct 30, 2006
Posts: 3
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

Joined: Jan 29, 2003
Posts: 8791
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
Greenhorn

Joined: Oct 30, 2006
Posts: 3
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
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Alan B Smith
Greenhorn

Joined: Oct 30, 2006
Posts: 3
i get it,thanks
 
GeeCON Prague 2014
 
subject: HELP