Newbi can anyone help with methods and classes

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 17
Reputation: grifflyn is an unknown quantity at this point 
Solved Threads: 0
grifflyn's Avatar
grifflyn grifflyn is offline Offline
Newbie Poster

Newbi can anyone help with methods and classes

 
0
  #1
Jan 12th, 2005
Hi i Have written some code at Uni for two programs

this is my first one

// filename: ArrayClient.java
// Author:
// Last Updated :Jan 2005
//
// Program to demonstrate how to provide a class
// of array utilities
//

public class ArrayClient
  1.  
  2. {
  3. public static void main (final String[] pArgs)
  4. {
  5. int [] tArray = new int [4];
  6.  
  7. tArray [0] = 11;
  8. tArray [1] = 22;
  9. tArray [2] = 33;
  10. tArray [3] = 44;
  11.  
  12. ArrayUtilities.outputArray (tArray);
  13.  
  14. ArrayUtilities.resetArray (tArray);
  15.  
  16. ArrayUtilities.outputArray (tArray);
  17.  
  18. }
  19. }
and this is the second piece of code i have written
  1.  
  2. // Filename: ArrayUtilities.java
  3. // Author
  4. // Last Updated Jan 2005
  5. // by
  6. // class that provides a number of Array Utilities
  7. //
  8. public class ArrayUtilities
  9. {
  10. // Method to reset an integer array so that
  11. // all elements have the value zero
  12.  
  13. public static void resetArray (final int [] pArray)
  14. {
  15. for (int i = 0; i < pArray.length; i++)
  16. {
  17. pArray [i] = 0;
  18. }
  19. }
  20.  
  21. // method to output the contents of an integer array
  22.  
  23. public static void outputArray (final int [] pArray)
  24. {
  25. for (int i = 0 ; i <pArray.length; i++)
  26. {
  27. System.out.print (pArray [i] + " ");
  28. }
  29. System.out.println();
  30.  
  31. }
  32.  
  33. // fliename sumArray method to add the integers of
  34. // an array together
  35.  
  36. public static void sumArray (final int [] pArray)
  37. {
  38. int tSum = 0;
  39.  
  40. for (int i = 0 ; i <tSum; i++)
  41. {
  42. tSum += pArray [i];
  43. }
  44. }
  45.  
  46.  
  47. }
my problem is when i wrote them at Uni they both compiled and worked (on a mac G5)
I FTP'd them home and now only the ArrayUtilities will compile. I re-wrote the ArrayClient file and it still wont compile this is the error message i get everytime i try to compile the ArrayClient file

C:\Documents and Settings\Administrator\Desktop\UNI\Programming\Programming2\week1\ArrayClient.java:20:
cannot resolve symbol symbol : variable ArrayUtilities location: class ArrayClient ArrayUtilities.outputArray (tArray);
C:\Documents and Settings\Administrator\Desktop\UNI\Programming\Programming2\week1\ArrayClient.java:22: cannot resolve symbol symbol : variable ArrayUtilities location: class ArrayClient ArrayUtilities.resetArray (tArray);
C:\Documents and Settings\Administrator\Desktop\UNI\Programming\Programming2\week1\ArrayClient.java:24: cannot resolve symbol symbol : variable ArrayUtilities location: class ArrayClient ArrayUtilities.outputArray (tArray);
3 errors
Tool completed with exit code 1

can anyone point me in the right direction as to what i am doing wrong.
any help will be appreciated
:p
If you worry you Die.
If you dont worry you Die.
SO DONT WORRY
:cool:
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 5
Reputation: geoff.ainger is an unknown quantity at this point 
Solved Threads: 1
geoff.ainger geoff.ainger is offline Offline
Newbie Poster

Re: Newbi can anyone help with methods and classes

 
0
  #2
Jan 12th, 2005
Hullo,

This looks very much like a classpath problem.

In order for the ArrayClient class to be compiled (or to run for that matter) it needs to "see" the ArrayUtilities class.

Try running:
javac -classpath . ArrayUtilities.java ArrayClient.java
to compile them. To run them try:
java -classpath . ArrayClient

Geoff
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Newbi can anyone help with methods and classes

 
0
  #3
Jan 12th, 2005
I noticed that you didn't have an instance of the ArrayUtilities class in your first project. I don't have a jdk on this computer so I can't test it or I would. But to me that looks like the problem.

You could do something like this:

ArrayUtilities ar = new ArrayUtilites();
ar.resetArray(arrayname);
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Newbi can anyone help with methods and classes

 
0
  #4
Jan 13th, 2005
Well, all methods in ArrayUtilities are static so can be called without an instance.
In fact, using a call of one of them on an instance could result in a warning (depending on compiler settings).

Compiling them doesn't give any errors at all here if they're (as they should be) in the same directory.

So it's no problem in the code.
try compiling using
javac -classpath . ArrayClient.java
and see what happens.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 17
Reputation: grifflyn is an unknown quantity at this point 
Solved Threads: 0
grifflyn's Avatar
grifflyn grifflyn is offline Offline
Newbie Poster

Re: Newbi can anyone help with methods and classes

 
0
  #5
Jan 13th, 2005
Hi to all that have replied and thanks but i haven't got a clue as to how to do this with the program i am using to write my code. Its a program called TextPad by "helios" and has been working fine and still does on on the ArrayUtilities code.
Could any one suggest another program that is easy to set up and free to download or cheap to buy. I do have net beans but find it very confusing
I guess could have another go at that if there are no other options

Originally Posted by geoff.ainger
Hullo,

This looks very much like a classpath problem.

In order for the ArrayClient class to be compiled (or to run for that matter) it needs to "see" the ArrayUtilities class.

Try running:
javac -classpath . ArrayUtilities.java ArrayClient.java
to compile them. To run them try:
java -classpath . ArrayClient

Geoff
:p
If you worry you Die.
If you dont worry you Die.
SO DONT WORRY
:cool:
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 17
Reputation: grifflyn is an unknown quantity at this point 
Solved Threads: 0
grifflyn's Avatar
grifflyn grifflyn is offline Offline
Newbie Poster

Re: Newbi can anyone help with methods and classes

 
0
  #6
Jan 13th, 2005
Hi to all who replied

I have just installed NetBeans and my programs work fine

thanks to all who replied

but i had to do something i had it on my machine a while ago and took it off becasue i wasnt comfortable with it but had to do something to get my course work done.
I will probably be back as this program isnt the easiest to code in but then again i havent got a clue on any of the other languages either.

Grifflyn
:p
If you worry you Die.
If you dont worry you Die.
SO DONT WORRY
:cool:
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Newbi can anyone help with methods and classes

 
0
  #7
Jan 13th, 2005
We used TextPad at school and I hated it.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Newbi can anyone help with methods and classes

 
0
  #8
Jan 14th, 2005
And so you've not learned a thing...
You still don't know how to use the compiler for example, which is what was your problem in the first place.

You took the easy way out which was to install an IDE with all its wizzards to do the work for you. Next time you're somewhere where you don't have that option you'll again be lost and come here asking the exact same question all over again.

NOONE should use an IDE unless and until they can do anything it does themselves, you haven't reached that stage yet and now you likely never will.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 17
Reputation: grifflyn is an unknown quantity at this point 
Solved Threads: 0
grifflyn's Avatar
grifflyn grifflyn is offline Offline
Newbie Poster

Re: Newbi can anyone help with methods and classes

 
0
  #9
Jan 14th, 2005
Originally Posted by jwenting
And so you've not learned a thing...
You still don't know how to use the compiler for example, which is what was your problem in the first place.

You took the easy way out which was to install an IDE with all its wizzards to do the work for you. Next time you're somewhere where you don't have that option you'll again be lost and come here asking the exact same question all over again.

NOONE should use an IDE unless and until they can do anything it does themselves, you haven't reached that stage yet and now you likely never will.
If i were a younger student i would accept criticism like that but being a 36 year old mature student i know that constructive criticism is better than in effects calling some one a cheat and a slacker.
NetBeans doesnt write the code for me i still have to think about what to write and how to get the program to work. and once i get my degree i will be usinig what ever software is avaiable to compile my programs
I do know how to use compilers but i had the problem with my machine at home and wanted a quick fix as we are under a short deadline to complete our tasks and we are set 7 per week and have to have them ready.
i didn't ask anyone to write my code for me which is cheating just how to get the programs to compile
I guess i might be looking for other forums to help with any issues i have if all i get is criticism like that and being insulted

Rgds Grifflyn
:p
If you worry you Die.
If you dont worry you Die.
SO DONT WORRY
:cool:
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Newbi can anyone help with methods and classes

 
0
  #10
Jan 14th, 2005
Originally Posted by jwenting
And so you've not learned a thing...
You still don't know how to use the compiler for example, which is what was your problem in the first place.

You took the easy way out which was to install an IDE with all its wizzards to do the work for you. Next time you're somewhere where you don't have that option you'll again be lost and come here asking the exact same question all over again.

NOONE should use an IDE unless and until they can do anything it does themselves, you haven't reached that stage yet and now you likely never will.
I don't think he meant it in a bad way. I have to say I agree. I started out learning vb.net and used visual studio.net as an IDE. When I switched to java I was a very lazy programmer because I has such a good IDE to use in vb.net. You would be suprised at how much you learn using the command line to compile and run your programs. Actually, I've got so use to it that I don't like using IDE. I simply like using a good Value Added Text Editor like jEdit to program in.

grifflyn, please don't leave this forum. Jwenting is very smart and good at helping people. It's just sometimes he has a bad way of wording things that sound insulting when their not suppose to be.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 4460 | Replies: 20
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC