Results 1 to 3 of 3
  1. #1
    twiggy62's Avatar
    twiggy62 is offline Member
    Join Date
    Feb 2010
    Posts
    26
    Rep Power
    0

    Default What's an easy way to test this code?

    Below is the code I have thus far. I want to be able to test the creation of all objects. What would be the easiest way to do this (using the main)?

    Java Code:
    // MusicCollection class holds an array of Artist objects and Recording objects
    public class MusicCollection {
    
        private Artist[] artistObjs = new Artist[5];
        private Recording[] recordingObjs = new Recording[5];
    
        // Artist class, member inner class of the MusicCollection class 
        public class Artist {
        }
    
        // Recording class holds a single Artist object and an array of Track objects
        public class Recording {
    
            private Artist artistObj = new Artist();
            private Track[] trackObjs = new Track[5];
    
            // Track class represents a single piece of music within a Recording object
            public class Track {
    
                private String trackName;
    
                public String getTrack() {
                    return trackName;
                }
            }
        }
    
        // Test the creation of all objects
        public static void main(String[] args) {
        }
    }
    The biggest room in the world, is room for improvement.

  2. #2
    jassi is offline Member
    Join Date
    Feb 2010
    Location
    Dehradun
    Posts
    5
    Rep Power
    0

    Default

    Debug your program in Eclipse IDE and open a window called Variables.

    You will see all your variables created there as you move on with your code

  3. #3
    thomasdevos's Avatar
    thomasdevos is offline Member
    Join Date
    Feb 2010
    Posts
    19
    Rep Power
    0

    Default

    hello twiggy62,
    all class is inner class excpet MusicCollection.
    so, to create all those objects, i feel you need special way to do it.

    with MusicCollection, just simply code like:
    Java Code:
    MusicCollection m = new MusicCollection();
    with Artist, it is inner class, so you have to do it like this:
    Java Code:
    MusicCollection.Artist a = m.new Artist();
    the same with Recording
    Java Code:
    MusicCollection.Recording r= m.new Recording();
    and, about Track, it is inner class of inner class , so it should be done like this:
    Java Code:
    MusicCollection.Recording.Track t=  r.new Track();
    below is whole java code, good luck:
    Java Code:
    // MusicCollection class holds an array of Artist objects and Recording objects
    public class MusicCollection {
    
        private Artist[] artistObjs = new Artist[5];
        private Recording[] recordingObjs = new Recording[5];
    
        // Artist class, member inner class of the MusicCollection class 
        public class Artist {
        }
    
        // Recording class holds a single Artist object and an array of Track objects
        public class Recording {
    
            private Artist artistObj = new Artist();
            private Track[] trackObjs = new Track[5];
    
            // Track class represents a single piece of music within a Recording object
            public class Track {
    
                private String trackName;
    
                public String getTrack() {
                    return trackName;
                }
            }
        }
    
        // Test the creation of all objects
        public static void main(String[] args) {
        	MusicCollection m = new MusicCollection();
        	MusicCollection.Artist a = m.new Artist();
        	MusicCollection.Recording r= m.new Recording();
        	MusicCollection.Recording.Track t=  r.new Track();
        	
        }
    }
    i hold 7 years develop exp. now i start a thread to share my knowlege about a j2ee project. welcome to participate.Study Java Through Real Java Project

Similar Threads

  1. in need of help (easy)
    By fasck in forum New To Java
    Replies: 5
    Last Post: 12-30-2009, 11:45 PM
  2. how easy it is?
    By ron87 in forum New To Java
    Replies: 0
    Last Post: 04-01-2009, 07:36 PM
  3. Not so easy is it.
    By Roy Gardiner in forum Introductions
    Replies: 0
    Last Post: 10-24-2008, 05:59 PM
  4. What does this mean (Very Easy)
    By Zebra in forum New To Java
    Replies: 6
    Last Post: 05-01-2008, 02:46 PM
  5. Replies: 0
    Last Post: 04-05-2008, 01:38 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
  •