orry kaplan

Ranch Hand
+ Follow
since Aug 03, 2016
Merit badge: grant badges
For More
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 orry kaplan

Henry Wong wrote:What version of Java are you using?



Build id: 20100617-1415
7 years ago


I have Month; written in the switch statement above but i'm getting a error saying "Cannot switch on a value of type String. Only convertible int values or enum constants are permitted".
what does this mean? can anyone help?
7 years ago

Henry Wong wrote:
When you try to print any object, that is not a string, the println() method will call the toString() method of the object, in order to get the string representation, so that it can print it.

Since your Data class, did not implement the toString() method, it will inherit it from its super class. And with the Object class, the toString() method returns the name of the class along with the Identity hash for the instance.

Henry




Would this be more appropriate?

7 years ago
i have my code here but whenever i print, a part of the print is showing up in an unreadable format. any help as to what i need to do?



prints:

Fred 21
Jo 43
Harry 78
Zoe 37
[Data@1540e19d, Data@677327b6, Data@14ae5a5, Data@7f31245a]
7 years ago

Dave Tolls wrote:

orry kaplan wrote:[
This is all of the code i have.



How can this be all the code?
There isn't even a class definition.



7 years ago

Carey Brown wrote:

orry kaplan wrote:This is all of the code i have. And my error message i got is, " The method PrintDataArray(ArrayList<Data>) is undefined for the type PJ1"


What is PJ1 ?



Thats just the name of the project. Do you know what the problem is and how i can possibly fix it?
7 years ago

Carey Brown wrote:2 things would help us help you: 1) show all of your code, 2) copy-n-paste error message(s) into your post.

PrintDataArray(ArrayA);

Do you have such a method? What argument is the method expecting?



This is all of the code i have. And my error message i got is, " The method PrintDataArray(ArrayList<Data>) is undefined for the type PJ1"
7 years ago

Ole Sandum wrote:Not using the wrapper classes, no. But it is possible the paper used the primitive types long and float (lowercase l and f), which can be converted between eachother. Are you sure you quoted the paper directly without changing the case of those letters?



100% quoted correctly, however it does say what happenes when F and L are removed however that should still present an invalid answer?
7 years ago
hi, i am trying to print these arrays however it is coming up with an error on one part (listed below)




I am sooo confused as to why this is showing, any help?
7 years ago

Ole Sandum wrote:Here you are trying to cast a reference of type Long to Float.

Note that to be able to successfully cast a reference to a type T, the object referred to by said variable must be of a subtype of T (or of T itself). The compiler is clever enough to see that this will never be the case for Float and Long, and does not allow the code to compile.



So basically it cannot be done?
7 years ago

Ole Sandum wrote:Hi, orry.

Primitives cannot be cast the same way reference variables can. Maybe you are talking about primitive type conversion? Or maybe you are trying to cast between the wrapper types Float and Long?

If you are trying to do the latter, that is impossible because none of those two classes inherits from the other.

Maybe it would help if you showed us some code showcasing the problem?



Well im working on some past papers and this question came up:

Long v1 = 10L;
Float v2 = 10.3F;

Observe what happens when you remove the L and F. Rewrite these lines using casting.


so so far i put this but no luck due to it saying they cannot be casted:

7 years ago
I am trying to cast a float to a long or a long to a float but every time java says i cannot cast them either way i try. Can they be casted?
7 years ago

Carey Brown wrote:Yep. That should work.

Do you need to print age as well?



Yeah I do but I wasn't sure how to add it in too, unless I duplicate the print line with GetName and change the second one to GetAge?
7 years ago

Carey Brown wrote:

Carey Brown wrote:You could have been extremely verbose like this:


In your case, because you have a print() method, you could have done this:

However, you COULD NOT have done this without a toString():





i have finalised this thinking i have finished the problem. do you think this seems correct?
7 years ago

Carey Brown wrote:

orry kaplan wrote:That code snip you put above, is that the solution to this? because even though i get that it cannot be printed unless it is toString, is there a way to print this list in a readable format without it as it seems a little confusing to use all the time.


Using toString() is considered the proper way to do it. You could have been extremely verbose like this:

This is not the path usually chosen because of the risks of errors being introduced during maintenance and modification. Also, toString() is quite often used during the debugging stage of development.

Note that inserting parenthesis, commas, field names (e.g. "Name:") into the String are all up to the designer. Whatever you need for meaningful output.


/
So can the toString be used on this program effectively
7 years ago