 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Gremlin Dude Guest
|
Posted: Wed Apr 27, 2005 10:56 am Post subject: Need help calling java classes |
|
|
Hi. I am a beginner in java so i may sound like a total prat here,
but here goes:
I have been given my university coursework to do. I have to make a
program whereby a customer ordering boxes is asked what attributes of
a box he/she wants from list we have been given, then work out a price
for the box. Anyhow, we have six box types, so a class for each, an
Input class for reading input from the keyboard and a main class.
now, obviously the program starts in main, but i need to go to the
Input class as soon as the program starts, so i can put in some info
from the keyboard, but my tutor says that we have to separate the main
and input classes(whereas i can see it being easier to shove it all in
the main class), so i need to know this: How do you call one class
from another in java? I know how to call methods in one class:
methodname();, but i need to access the input class from the main
class. Is this possible or am i barking up the wrong tree? Help is
much appreciated.
Thanks
----------
Stuart
|
|
| Back to top |
|
 |
kaeli Guest
|
Posted: Wed Apr 27, 2005 12:44 pm Post subject: Re: Need help calling java classes |
|
|
In article <5d8f90ea.0504270256.1b97266f (AT) posting (DOT) google.com>,
[email]gremlin_dude (AT) hotmail (DOT) com[/email] enlightened us with...
| Quote: | I have been given my university coursework to do. I have to make a
program whereby a customer ordering boxes is asked what attributes of
a box he/she wants from list we have been given, then work out a price
for the box. Anyhow, we have six box types, so a class for each, an
Input class for reading input from the keyboard and a main class.
now, obviously the program starts in main, but i need to go to the
Input class as soon as the program starts, so i can put in some info
from the keyboard, but my tutor says that we have to separate the main
and input classes(whereas i can see it being easier to shove it all in
the main class), so i need to know this: How do you call one class
from another in java? I know how to call methods in one class:
methodname();, but i need to access the input class from the main
class. Is this possible or am i barking up the wrong tree? Help is
much appreciated.
|
Wrong tree. Wrong forest, too. :)
You want to instantiate the input class, I assume?
Input input = new Input();
The input class will not have a main method. You don't "call" the class. You
call the methods in it from the main method of the other class.
The Input class should have methods in it, like getInput or something.
public String getInput()
Then you call that.
String str = input.getInput();
HTH
--
--
~kaeli~
Found God? If nobody claims Him in 30 days, He's yours to
keep.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
|
|
| Back to top |
|
 |
. Guest
|
Posted: Wed Apr 27, 2005 6:30 pm Post subject: Re: Need help calling java classes |
|
|
On Wed, 27 Apr 2005, Gremlin Dude wrote:
| Quote: | Hi. I am a beginner in java so i may sound like a total prat here,
but here goes:
I have been given my university coursework to do. I have to make a
program whereby a customer ordering boxes is asked what attributes of
a box he/she wants from list we have been given, then work out a price
for the box. Anyhow, we have six box types, so a class for each, an
Input class for reading input from the keyboard and a main class.
now, obviously the program starts in main, but i need to go to the
Input class as soon as the program starts, so i can put in some info
from the keyboard, but my tutor says that we have to separate the main
and input classes(whereas i can see it being easier to shove it all in
the main class), so i need to know this: How do you call one class
from another in java? I know how to call methods in one class:
methodname();, but i need to access the input class from the main
class. Is this possible or am i barking up the wrong tree? Help is
much appreciated.
|
Either your university has failed to teach you about object oriented
programming or your not understanding it. Either way, you are looking at
the problem incorrectly.
The tutor wants you to create an object that gets the input. This will be
a class. You will need a second class that holds main. The main method
will then create (instantiate) an instance of the input class. You would
then use that object to get input from the user. The input from the user
would be stored in the input class. You could then use the instance of
input class to request the input from the user.
If this does not make sense to you then get a good book on Java
programming. Not one of those Mastering Java in 21 Days type books but one
that explains the concepts of Java. It should talk about things like
abstraction and encapsulation. If you don't understand these concepts you
will have a very hard time doing your homework.
In case your wondering why you shouldn't just put everything in the main
class, they are giving you a simple project that you can envision the
entire thing without effort. This is because they know you don't have the
time to create something so complex you need to break it apart into
sub-groups. Still, they want you to develop this skill.
They want you to be able to write a program with 500,000 lines of code.
One class with 500,000 lines of code would be incredibly difficult to
maintain.
You want the skill to be able to create 1000 classes with 500 lines of
code each. They you can focus on one class at a time. Dealing with 500
lines of code should not be a problem.
--
Send e-mail to: darrell dot grainger at utoronto dot ca
|
|
| Back to top |
|
 |
Hal Rosser Guest
|
Posted: Wed Apr 27, 2005 8:52 pm Post subject: Re: Need help calling java classes |
|
|
speaking of classes:
go to them - don't cut
the instructor should clear this up for you
|
|
| Back to top |
|
 |
Thomas G. Marshall Guest
|
Posted: Thu Apr 28, 2005 12:38 am Post subject: Re: Need help calling java classes |
|
|
"." coughed up:
| Quote: | On Wed, 27 Apr 2005, Gremlin Dude wrote:
Hi. I am a beginner in java so i may sound like a total prat here,
but here goes:
I have been given my university coursework to do. I have to make a
program whereby a customer ordering boxes is asked what attributes of
a box he/she wants from list we have been given, then work out a
price for the box. Anyhow, we have six box types, so a class for
each, an Input class for reading input from the keyboard and a main
class. now, obviously the program starts in main, but i need to go
to the Input class as soon as the program starts, so i can put in
some info from the keyboard, but my tutor says that we have to
separate the main and input classes(whereas i can see it being
easier to shove it all in the main class), so i need to know this:
How do you call one class from another in java? I know how to call
methods in one class: methodname();, but i need to access the input
class from the main class. Is this possible or am i barking up the
wrong tree? Help is much appreciated.
Either your university has failed to teach you about object oriented
programming or your not understanding it. Either way, you are looking
at the problem incorrectly.
The tutor wants you to create an object that gets the input. This
will be a class. You will need a second class that holds main. The
main method will then create (instantiate) an instance of the input
class. You would then use that object to get input from the user. The
input from the user would be stored in the input class. You could
then use the instance of input class to request the input from the
user.
If this does not make sense to you then get a good book on Java
programming. Not one of those Mastering Java in 21 Days type books
but one that explains the concepts of Java. It should talk about
things like abstraction and encapsulation. If you don't understand
these concepts you will have a very hard time doing your homework.
In case your wondering why you shouldn't just put everything in the
main class, they are giving you a simple project that you can
envision the entire thing without effort. This is because they know
you don't have the time to create something so complex you need to
break it apart into sub-groups. Still, they want you to develop this
skill.
They want you to be able to write a program with 500,000 lines of
code. One class with 500,000 lines of code would be incredibly
difficult to maintain.
|
However, that is how most EE's I've met are comfortable programming.
Forget the class. Entire app----one method.
Aw, c'mon, it's only half true.... '''''''''
| Quote: |
You want the skill to be able to create 1000 classes with 500 lines of
code each. They you can focus on one class at a time. Dealing with 500
lines of code should not be a problem.
|
--
Unix users who vehemently argue that the "ln" command has its arguments
reversed do not understand much about the design of the utilities. "ln
arg1 arg2" sets the arguments in the same order as "mv arg1 arg2".
Existing file argument to non-existing argument. And in fact, mv
itself is implemented as a link followed by an unlink.
|
|
| Back to top |
|
 |
Gremlin Dude Guest
|
Posted: Fri Apr 29, 2005 1:13 pm Post subject: Re: Need help calling java classes |
|
|
Hi. Thanks for the help people, i have got it now. other problems
have arisen since, but I might be able to solve them. thanks again!
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|