Using an array from one class in another??


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Using an array from one class in another??

  1. #1
    Join Date
    Nov 2005
    Posts
    4

    Using an array from one class in another??

    hi,

    I need to make a Video store management system and am having some troubles. I need a class called TitleList that has an array that contains information about films titles. This will include film name, actors, director and code.

    I also need to create a class called VideoList with an array containing information about videos. This will include information such as reference number and information extended from Title (actors, director etc).

    When making the interface I need to be able to search the Title array to get a Title and the use this information to create a new Video to add to the Video array.

    So, my question is how can I get information from the Title array from within the VideoList class???

    I hope it makes sense and I really appreciate any help.

    thanks

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    it sounds like you will be implementing an array(?) or arraylist(?) of Title objects. Search your array/list for the Title object you're looking for, then extract the needed information to populate fields in your Video object.

  3. #3
    Join Date
    Nov 2005
    Posts
    4
    Quote Originally Posted by nspils
    it sounds like you will be implementing an array(?) or arraylist(?) of Title objects. Search your array/list for the Title object you're looking for, then extract the needed information to populate fields in your Video object.
    I think I've got it sorted, thanks for your help. I now have another problem. I will have one class that calls methods from other classes. The problem I have is exiting one of the methods. I was using System.exit(0) which seems to close all the running methods, not just the one that called it (if that makes sense). Is there a method that will stop just the one method.

    Thanks

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    System.exit(0) calls Runtime.runtime.exit() which shuts down the java virtual machine. That is why all execution terminates.

    What are you trying to accomplish? Catch an exception? Break out of a loop? Returning from a method? Better determine why you might be looking to exit() and then design a more appropriate environment in which to expect that event.

  5. #5
    Join Date
    Nov 2005
    Posts
    4
    I have a some options for the user (edit borrowers, edit titles, edit videos).

    If the user chooses edit borrowers they will be presented with another set of options (add borrower, remove borrower, display all borrowers and exit).

    When the user chooses exit I want it to exit the edit borrowers method and return to the orignial method that will allow the user to select between the original options (edit borrowers, edit titles, edit videos).

    It will be similar for edit titles and edit videos.

    The problem I have is that my exit method uses system.exit(0) which shuts down the entire running application.

  6. #6
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Then what you need to do is write your various methods so that if "exit" is chosen you return to your "main menu" method.

  7. #7
    Join Date
    Nov 2005
    Posts
    4
    Thanks, I've sorted it now. I changed from using if and else statements to using a switch statement. This tidied my code up allowing me to spot a slight mistake in my while loop. I fixed it and it now exits when it's supposed to.

    Thanks for your help

Similar Threads

  1. Return an array from a class method
    By nubira in forum C++
    Replies: 5
    Last Post: 11-04-2005, 02:53 PM
  2. array from a seperate class
    By sunnny in forum Java
    Replies: 2
    Last Post: 09-26-2005, 05:39 AM
  3. array initializer for class member
    By jab630 in forum C++
    Replies: 2
    Last Post: 09-21-2005, 08:49 AM
  4. Replies: 5
    Last Post: 10-17-2002, 01:58 PM
  5. Object Array ? Do you Worth it
    By ashish in forum Java
    Replies: 1
    Last Post: 05-23-2002, 07:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center