Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2005

Tip: Looking for answers? Try searching our database.

Need help calling java classes

Thread view: 
Gremlin Dude - 27 Apr 2005 11:56 GMT
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
kaeli - 27 Apr 2005 13:44 GMT
In article <5d8f90ea.0504270256.1b97266f@posting.google.com>,
gremlin_dude@hotmail.com enlightened us with...
> 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
[quoted text clipped - 10 lines]
> 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

Signature

--
~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

"." - 27 Apr 2005 19:30 GMT
> Hi.  I am a beginner in java so i may sound like a total prat here,
> but here goes:
[quoted text clipped - 13 lines]
> 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.

Signature

Send e-mail to: darrell dot grainger at utoronto dot ca

Thomas G. Marshall - 28 Apr 2005 01:38 GMT
"." coughed up:

>> Hi.  I am a beginner in java so i may sound like a total prat here,
>> but here goes:
[quoted text clipped - 42 lines]
> 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.... :-P'''''''''

> 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.

Signature

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.

Hal Rosser - 27 Apr 2005 21:52 GMT
speaking of classes:
go to them - don't cut
the instructor should clear this up for you
Gremlin Dude - 29 Apr 2005 14:13 GMT
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!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.