Vince Stout

Greenhorn
+ Follow
since Apr 13, 2012
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vince Stout

Just as a tip. It is always better to grab the whole line when getting user input unless you specifically need it broken into parts. For example:

With this method you will never have to worry about not consuming an eol character.
11 years ago
+1 @ Mr. Burke:
A simple text editor and the command line will give you a much stronger grasp of the basics when starting out. The link in my signature will prove invaluable as well.

+1 @ Sheriff Ritchie:
NotePad++ is an awsome editor and supports syntax highlighting for most languages
11 years ago
although a 'while' loop will work fine, when you know how many iterations you need a 'for' loop is more appropriate.
11 years ago
As previously stated, d/l eclipse and the android sdk. Here http://www.youtube.com/playlist?list=PL34F010EEF9D45FB8 is a great collection of video tutorials to get you started. There are about 200 in all; covering everything from setting up the sdk to advanced android programming techniques.
11 years ago
Hello all. Thanks for the replies. Sorry it took so long to get back, but its been a busy week.

@Marcus - thanks for the example on precision loss during conversion. I had figured there would be some, but its cool to see it broken down.

@Campbell - yeah, I saw some interesting methods in those classes when doing research for the above assignment. Thanks for the example. Oh yeah, lol.
11 years ago
Hello, I am having some problems with an assignment.

The assignment is to create a generic class with a type parameter 'T' which needs to be constrained to an upper bound: Number. The class needs to have one field, an ArrayList of type 'T'. I need to provide 3 methods: add() to add an element to the list, largest() to return the largest value in the list and smallest() to do the opposite of largest.

The problem is that beings Number is the superclass of 'T', I am getting errors when trying to use greater/lessthan operators and the compareTo() method to find the largest/smallest value. This is because Number does not support either of these operations.

My question is how can I get my values without using greater/lessthan operators or the compareTo() method? I feel like I'm missing something. It doesn't seem like this should be a hard assignment, but I was up all last night working on it. I tried writing overloaded helper methods to call from largest() named getLargest() which had different returns (Integer, Double etc...). I had tried casting 'T' to the method when calling it but that only worked when I had the Integer method written. As soon as I wrote the Double version an error was thrown that getLargest() was already defined.

Any insight would be greatly appreciated, code to follow.

Code:


Edit: I have come up with a way to do this that seems to work, but I'm not sure if it will accomodate all subclasses of number. So far I have tested it on Integer and Long.

Code for new largest() method


Re-Edit: I've tested everything pretty thoroughly and this the revised largest method seems to be the way to go. My biggest fear was that the long value would overflow but it didn't. I've now written the smallest() method and have tested the class with types: Short, Float, Double, Long and Integer. I have not messed with BigDecimal, BigInteger etc... but considering they all take a long value in their constructor, and my method will accommodate long values, I think it will work ok.

Any additional insight would still be appreciated however.
11 years ago
That's unfortunate. If possible, I would suggest changing classes, but I know that's not always an option. Here are two links that will hopefully help you

This, is a link to the new bostons java tutorials. They are video tutorials and will walk you through from the ground up.

And here is a link to oracles java tutorial trail.

Between those two sites you should be able to get a good grasp on the basics.

11 years ago
Has your class covered loops and arrays?
11 years ago
Are you familiar with what's happening in the original code?
11 years ago
Let the compiler help you. It says your problem is on line 7. That is where you start looking. What looks different between line 7 in the book and yours?

To use code tags put code=java between sqauare brackets above your first line of code, and /code between brackets after your last line of code
11 years ago
Well, for starters, take a look at the code you need to modify. There is basically three blocks; one to create your objects, one to describe the cat, and the other for the bird. What commands in those blocks are repetative? This is the code you'll want to run in your loop. Your book should have syntax for an enhanced for loop.

As for the array and arraylist; it looks like you have to write your program once using an array, and once using an arraylist. Beings (I'm assuming) cat and robin inherit from animal, you should create an array and arraylist of animal objects
11 years ago
You said path is set to '%JAVA_HOME%\bin' if that's correct, you need to remove the '\bin' because its already defined in %JAVA_HOME%. And you should also add that to the end of your PATH variable, not the beginning.

You can also remove CLASSPATH, that's more for if you want the compiler (javac) to find your own 3rd party libraries and such without using the -cp switch.
11 years ago
As stated earlier, make sure you add the 'bin' folder (the folder where javac is) to your path. It should look something like this --> C:\Java\jdk1.6.0_30\bin\

Here, is a tutorial on doing so
11 years ago
You still need to look closer at your if statement on line 20. As stated earlier, it can never be true. And even if it could, you are not doing anything to correct the error that caused it to be.
11 years ago
What you need to do is figure out a way to check each number generated against the previously generated numbers.
11 years ago