|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On March 25 2014 00:51 LonelyCat wrote:So Comparable forces you (as you know) to implement the compareTo method. This method is used by other methods (for example Collections.sort) to determine which of 2 objects is "larger". So lets take your Investment class and say we want to say the price of an investment is double totalPrice = numShares*price;
and an investment is "greater" than another investment if its total price is higher than the other: public int compareTo( Investment rhs ){ /* Find out this objects total price*/ double thisTotalPrice = this.numShares*this.price;
/* Find out rhs total price */ double rhsTotalPrice = rhs.numShares*rhs.price;
/* Return the difference (this - rhs)*/ return thisTotalPrice - rhsTotalPrice; }
+ Show Spoiler + Note that this implementation will not work as numShares and price are declared as private, so you need getters/setters to access them.
The important thing is: If this > rhs then the returned value is > 0. If this .equals(rhs) then the return value is == 0 (this is NOT enforced, however it is good practice). if this < rhs then the returned value is < 0.If we then were to do: ArrayList<Investment> investments = new ArrayList<Investment>(); /* ... Fill ArrayList ...*/ Collections.sort(investments);
then ArrayList<Investment>.get(0) would have the lowest total price investment (as the .sort method sorts in ascending order). Hope this helps somewhat
Yes that helped a lot, thank you! I'm still confused about the difference between the comperable and iterable for my Account class that implements both. I know the iterable is passing the list of portfolios, how exactly am I to use this with the list of portfolios. Does iterable also use Collections.sort?
|
On March 24 2014 19:04 endy wrote: Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline.
If you're interested in game development, I recommend Game Closure. It's open source and they have a pretty good dedicated community to answering questions about the framework.
|
On March 25 2014 01:21 Days wrote:
Yes that helped a lot, thank you! I'm still confused about the difference between the comperable and iterable for my Account class that implements both. I know the iterable is passing the list of portfolios, how exactly am I to use this with the list of portfolios. Does iterable also use Collections.sort? Don't implement the iterable on the Account class. It makes no sense from a design/OO-perspective.
|
I agree with the previous poster, however if you're really set on it then you could do:
class Account implements Comparable<Account>, Iterable<Portfolio> { private String accountId; private List <Portfolio> portfolios; @Override public int compareTo(Account obj){ return 0; } void addPortfolio( Portfolio obj2 ){ };
public Iterator<Portfolio> iterator(){ return portfolios.iterator(); }
Iterable does not have anything to do with Collections, for example:
public class Set implements Iterable, Collections
is the java Set class - it implements iterable (so you know you can get an iterator over the set) as well as Collections, so you can call any Collections method on the Set too (like Collections.sort(Set)).
If you want to use iterable what you probably want to do is not implement iterable but instead do:
class Account implements Comparable<Account> { private String accountId; private List <Portfolio> portfolios; @Override public int compareTo(Account obj){ return 0; } void addPortfolio( Portfolio obj2 ){ };
public Iterator<Portfolio> getPortfolioIterator(){ return portfolios.iterator(); }
|
Ahh okay it's all making sense now. Technically it doesn't make sense to implement iterable since the Iterator already does what it needs to do without the use of implementing iterable. It would basically be redundant to implement iterable. Thank you guys lots!
Edit: I hope that makes sense what I just said from a logical point, if not you're welcome to correct me :D
|
On March 24 2014 19:04 endy wrote: Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline. Using JS is usually fine, however there are areas where a native implementation is better. But that depends on what you want to do. I used PhoneGap a while back for several Apps and it worked. I can't say anything about Appcelerator but I guess in the end it comes down to what do you need and which suits you better 
As for making the app offline capable, you simply put all data into the app, and ship it with it. Or you download files on demand and store them in the app. As for database, the frameworks have a database api you can use.
|
On March 24 2014 20:04 sluggaslamoo wrote:Show nested quote +On March 24 2014 19:04 endy wrote: Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline. Appcelerator Titanium. Nothing else comes close.
This looks pretty good, I will give this a try first. Thanks!
On March 25 2014 01:59 Athos wrote:Show nested quote +On March 24 2014 19:04 endy wrote: Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline. If you're interested in game development, I recommend Game Closure. It's open source and they have a pretty good dedicated community to answering questions about the framework.
Not interested in games for now, but thank you.
On March 25 2014 18:25 Encdalf wrote:Show nested quote +On March 24 2014 19:04 endy wrote: Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline. Using JS is usually fine, however there are areas where a native implementation is better. But that depends on what you want to do. I used PhoneGap a while back for several Apps and it worked. I can't say anything about Appcelerator but I guess in the end it comes down to what do you need and which suits you better  As for making the app offline capable, you simply put all data into the app, and ship it with it. Or you download files on demand and store them in the app. As for database, the frameworks have a database api you can use.
Hmm ok, I just feel that JS is fine for scripting as its name indicates. But I don't think you can write clean, easy to maintain and more importantly re-usable code with JS as you could with Java. Thanks!
|
On March 25 2014 19:07 endy wrote:Show nested quote +On March 24 2014 20:04 sluggaslamoo wrote:On March 24 2014 19:04 endy wrote: Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline. Appcelerator Titanium. Nothing else comes close. This looks pretty good, I will give this a try first. Thanks! Show nested quote +On March 25 2014 01:59 Athos wrote:On March 24 2014 19:04 endy wrote: Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline. If you're interested in game development, I recommend Game Closure. It's open source and they have a pretty good dedicated community to answering questions about the framework. Not interested in games for now, but thank you. Show nested quote +On March 25 2014 18:25 Encdalf wrote:On March 24 2014 19:04 endy wrote: Anyone has a nice framework to recommend to develop cross platform mobile apps? Most of them, like PhoneGap seem to be based on Javascript? Is Javascript powerful/robust enough? I don't think it can compare with a solid object oriented language.
edit: Also not very sure of how I can use a local database like Sqlite when using such a framework, or how to make my application work when offline. Using JS is usually fine, however there are areas where a native implementation is better. But that depends on what you want to do. I used PhoneGap a while back for several Apps and it worked. I can't say anything about Appcelerator but I guess in the end it comes down to what do you need and which suits you better  As for making the app offline capable, you simply put all data into the app, and ship it with it. Or you download files on demand and store them in the app. As for database, the frameworks have a database api you can use. Hmm ok, I just feel that JS is fine for scripting as its name indicates. But I don't think you can write clean, easy to maintain and more importantly re-usable code with JS as you could with Java. Thanks!
http://coffeescript.org/
Java has pretty horrid code re-usability actually, but I think I've beaten the horse to death enough over that.
|
On March 12 2014 08:47 Cyx. wrote: e: so I guess I should tell you guys how my 'command line interview' went... it was not as complex as previously thought, I just had to write a couple of scripts and fix some bugs in some stuff. It was on the command line on Ubuntu so all the stuff I had been worrying about for the last couple days was still pretty useful, but I didn't have to know how to grep anything or anything dumb like that ^^
second update: I got the job! So I get to actually code things for four months this summer instead of waiting tables, and someone is actually going to pay me for it... which is as good as I could have hoped for in second year =D next year I'll try and get an internship somewhere involved with gaming but for now I'm just satisfied that all the programming I've done over the last few years is actually going to pay me for once =D
|
Congrats man! I know the feeling!
|
Can someone recommend me good books on OOP, TDD and MVVM, maybe AOP? Not so much introductory material, but books that "lay down the law", clear and precise. Not all in one book of course, but rather one or two books for each topic.
|
How do you debug a timeout in .net 4.0?
![[image loading]](http://i.imgur.com/DLbyakH.png) We deployed on amazon. This works when you run the site locally on amazon. It also works when I run the site on my machine in visual studio. I can't seem to find anything in the log files that might help.
The problem is that nothing returns. No error code.
It works if you make the app bind on port 80, but we have two different parts of the site that are currently running on different ports.
|
Fire up Wireshark or http://www.telerik.com/fiddler - then you have an idea of what's being sent back and forth, or the lack thereof, which should help you
|
|
|
Hello TL programmers, I have question for you.
I am an engineering student who took a C++ for engineering course (basic stuff) and have been using the language to solve larger problems that I don't want to do or can't do in excel. When using it for a recent modeling program, I noticed the larger the program got, the more frequently it would inexplicably crash. No errors of any sort, and after rebooting and recompiling it would often run just fine.
Why is it doing this and how do I make it stop? Is the computer trying to do the calculations too fast and I need to set a limit to how fast it does them (opening the task manager I saw the CPU would often be running at 98%), or is it a memory problem (I often get a blue screen talking about a memory dump)? This kind of problem is outside of my knowledge base, and I feel the programmers must have dealt with these kinds of problems a long while ago. Any advice or reading material suggestions on the issue would be appreciated.
|
Well, there's got to be a baseline consensus on OOP at least.
Anyways, thanks for the suggestions!
|
On March 28 2014 01:51 spinesheath wrote:Well, there's got to be a baseline consensus on OOP at least. Anyways, thanks for the suggestions!
OOP designs does differ a lot depending on implementation. OOP for C++ is different than OOP from Java, etc... If you look at just one language, there's probably a good book that provides an excellent set of rules to live by. It's been some time since I did any heavy lifting in any OOP language though, so I don't have any suggestions.
Except don't use Exceptions if you're using C++, because unexpected arbitrary length code execution is bad.
|
|
|
On March 28 2014 01:31 gargantotang wrote: Hello TL programmers, I have question for you.
I am an engineering student who took a C++ for engineering course (basic stuff) and have been using the language to solve larger problems that I don't want to do or can't do in excel. When using it for a recent modeling program, I noticed the larger the program got, the more frequently it would inexplicably crash. No errors of any sort, and after rebooting and recompiling it would often run just fine.
Why is it doing this and how do I make it stop? Is the computer trying to do the calculations too fast and I need to set a limit to how fast it does them (opening the task manager I saw the CPU would often be running at 98%), or is it a memory problem (I often get a blue screen talking about a memory dump)? This kind of problem is outside of my knowledge base, and I feel the programmers must have dealt with these kinds of problems a long while ago. Any advice or reading material suggestions on the issue would be appreciated.
It sounds like you probably have one or more memory leaks somewhere in the program.
This causes your program to take up more and more memory until it crashes.
There are two solutions to this for you: Look up how to manage memory properly in C++, or use a language such as Python, Java, or C# that has garbage collection that deals with memory management for you.
|
Yeah, if you're using new/delete in C++ without boxing it into a constructor/destructor pair, you're doing it wrong.
|
|
|
|
|
|