Results 1 to 3 of 3
- 02-08-2010, 11:57 AM #1
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.
- 02-08-2010, 11:58 AM #2
Member
- Join Date
- Feb 2010
- Location
- Dehradun
- Posts
- 5
- Rep Power
- 0
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
- 02-10-2010, 09:41 AM #3
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:
with Artist, it is inner class, so you have to do it like this:Java Code:MusicCollection m = new MusicCollection();
the same with RecordingJava Code:MusicCollection.Artist a = m.new Artist();
and, about Track, it is inner class of inner class , so it should be done like this:Java Code:MusicCollection.Recording r= m.new Recording();
below is whole java code, good luck:Java Code:MusicCollection.Recording.Track t= r.new Track();
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
-
in need of help (easy)
By fasck in forum New To JavaReplies: 5Last Post: 12-30-2009, 10:45 PM -
how easy it is?
By ron87 in forum New To JavaReplies: 0Last Post: 04-01-2009, 06:36 PM -
Not so easy is it.
By Roy Gardiner in forum IntroductionsReplies: 0Last Post: 10-24-2008, 04:59 PM -
What does this mean (Very Easy)
By Zebra in forum New To JavaReplies: 6Last Post: 05-01-2008, 01:46 PM -
Test Advisory Panel-Telecommute- Test your Java skills + share insights on Java tests
By michelle in forum Jobs OfferedReplies: 0Last Post: 04-05-2008, 12:38 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks