Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Instance Class
Index -> Programming, Java -> Java Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
copthesaint




PostPosted: Thu Oct 15, 2009 1:50 pm   Post subject: Instance Class

This is my completly remade holder class. Ive spent the last two weeks workin on it. I havn't gotten to test it yet, but It does compile.
Please comment on my class, and everything is commented.

/**
*Instance Class
*2.0
*Christian Olienick Plourde
*
*Description: A unique class That allows you to create values
*and destroy them. With this you can make flexable arrays,
*two dimentional arrays with differents lengths, and remove
*parts of arrays.
* _____________________________________________________
*|Holds Values whitout having to declair variables
*|_____________________________________________________
*|Removal Methods: removeIntParts, removeDoubleParts,
*|removeInt, removeDouble
*|
*|Creation Methods: newInt, newDouble, newIntArray,
*|newDoubleArray, extendIntArray,extendDoubleArray
*|
*|Modifying Methods: setInt, setDouble, setIntArray,
*|setDoubleArray, setArrayIntArray, setArrayDoubleArray
*|
*|Return Methods: returnInt, returnDouble,
*|returnIntArray, returnDoubleArray, returnIntArrayPart
*|returnDoubleArrayPart
*|_____________________________________________________
*/
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Thu Oct 15, 2009 5:46 pm   Post subject: RE:Instance Class

Again, not to discourage you, but this is almost entirely duplicated effort. The JVM provides you with built-in classes for all of these requirements, all of which are faster than your implementation (and tested!). See java.util.List and java.util.Map.

Storing variable-length "arrays" of integers or doubles (note that you never need to manually extend anything):
Java:

List<Integer> ints = new ArrayList<Integer>();
ints.add ( 5 );

List<Double> doubles = new ArrayList<Double>();
doubles.add ( 3.1415 );


Removing elements from these lists:
Java:

ints.remove ( 0 );  // Removes the 0th element, without leaving empty spaces.
doubles.remove ( 10 ); // Removes the 11th element, without leaving empty spaces.


Mapping from "some string" to ( some object, integer or double or float or... )
Java:

Map<String, Integer> = new HashMap<String, Integer>();
map.put ( "twelve", 12 );
System.out.println ( map.get ( "twelve" ) );  // this will output 12.

// You can substitute the name of any class for "Integer" in the above to store arbitrary objects.


You also still have the drawback that I need to change your source to use the class adequately in my code (here, I'm referring to maxValues = 100, which is commented with "change to fit how many values you want to hold"). Worse, I may not know that information myself!
copthesaint




PostPosted: Thu Oct 15, 2009 6:32 pm   Post subject: Re: Instance Class

DemonWasp wrote:

Removing elements from these lists:
Java:

ints.remove ( 0 );  // Removes the 0th element, without leaving empty spaces.
doubles.remove ( 10 ); // Removes the 11th element, without leaving empty spaces.



First of all mine doesn't leave empty Spaces also Smile Look at the Trim method I made.

DemonWasp wrote:

Mapping from "some string" to ( some object, integer or double or float or... )
Java:

Map<String, Integer> = new HashMap<String, Integer>();
map.put ( "twelve", 12 );
System.out.println ( map.get ( "twelve" ) );  // this will output 12.

// You can substitute the name of any class for "Integer" in the above to store arbitrary objects.



Second My class does the same, but allows you to choose how many values to return, and if it's an array of just by it's self, and once
I have perfected the class for ints and doubles "or close enough :p", I'll add char and boolean and String. So on and so on.

DemonWasp wrote:

Storing variable-length "arrays" of integers or doubles (note that you never need to manually extend anything):


Yea lol I know, but you do need to extend the length with my class. If you don't, it will just keep running but it won't set the value.

DemonWasp wrote:

Again, not to discourage you, but this is almost entirely duplicated effort. The JVM provides you with built-in classes for all of these requirements, all of which are faster than your implementation (and tested!). See java.util.List and java.util.Map


Lol If you try to discourage me, I'll just ignore you anyways ;p. I am still working on my class aswell ;p and by the time I'm done, It will be very useful.
Also FYI, I'm not copying it Smile I just think of everything tha could be useful.
DemonWasp




PostPosted: Fri Oct 16, 2009 8:38 am   Post subject: Re: Instance Class

copthesaint @ Thu Oct 15, 2009 6:32 pm wrote:

First of all mine doesn't leave empty Spaces also Smile Look at the Trim method I made.


That was my point. I did read your code, and I did see the comment that noted that it did not leave empty spaces. I was pointing out that the behaviour of a List is exactly the same.

copthesaint @ Thu Oct 15, 2009 6:32 pm wrote:

Second My class does the same, but allows you to choose how many values to return, and if it's an array of just by it's self, and once
I have perfected the class for ints and doubles "or close enough :p", I'll add char and boolean and String. So on and so on.


Returning a sub-portion of a List:
Java:

List<Integer> myList = new ArrayList<Integer>();
// some code that adds values to myList would go here...
List<Integer> subListing = myList.subList ( start, end );


copthesaint @ Thu Oct 15, 2009 6:32 pm wrote:

Yea lol I know, but you do need to extend the length with my class. If you don't, it will just keep running but it won't set the value.


That sounds like poor behaviour. If something fails, you need to throw an Exception or otherwise report an error. It's up to the caller whether the error should be ignored or dealt with somehow.


My point with this is that unless you're specifically doing this to learn about algorithms, I don't see the point. The implementations you have posted are a good first attempt, but aren't going to stand up to what you can do with the classes provided by the JVM. If you are attempting to learn about algorithms, of course, go right ahead.

One final suggestion: learn about generics, because they'll make your code way, way simpler, easier to correct, and more generally useful. Instead of having to write code for ints, code for Strings, code for doubles, you can write code for "whatevers" and your class will magically work with anything from ints to ExtremelyComplexObjects.
copthesaint




PostPosted: Thu Sep 30, 2010 6:47 pm   Post subject: RE:Instance Class

Not trying to bother anyone by bumping this... lol But DemonWasp, do you mine posting a simple example of generics? :p I kinda abandoned working on it for a long while Very Happy but now that I have grade 12 programing class soon, I want to get even further ahead of the game! Smile. If anyone else has a relatively simple and also Very complex Uses of generics "helps me learn looking though code faster" Then it would be really appreciated if you posted it.
[Gandalf]




PostPosted: Fri Oct 01, 2010 9:14 am   Post subject: RE:Instance Class

He posted a link to the official Java tutorial on generics in his last post:
http://java.sun.com/docs/books/tutorial/java/generics/index.html

There are plenty of relatively simple examples on how to use generics there. If you have a more specific question, create a new thread in the help section. Smile
wtd




PostPosted: Fri Oct 01, 2010 4:58 pm   Post subject: RE:Instance Class

The Introduction to Java deals specifically with generics.
copthesaint




PostPosted: Sat Oct 02, 2010 2:13 pm   Post subject: RE:Instance Class

I know, however I was wondering if I could just get some examples from someone because I hate reading Very Happy. If no one has examples however I will look for myself then :/.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: