Results 1 to 11 of 11
Thread: Trying to learn methods.
- 02-05-2013, 03:03 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Trying to learn methods.
I'm trying to make a simple program so that in the main function the user should only have to write value.addera(); or value.subtrahera(); and the program will either +1 or -1 on the starting value. i'm running into a strange error that says
here is my code:Java Code:calc@5acac877
andJava Code:public class Räknare { public static void main(String[] arg) { calc value = new calc(); value.dec(7, 5 , 10); // start, min, max value.addera(); String show = value.toString(); System.out.println(show); } }
Java Code:public class calc { int minvärde,maxvärde,startvärde; public void dec(int start,int min, int max) { if(start < min || start > max) { System.out.println("Ditt värde gick över gränsen"); } if(min == 0 && max == 0) { min = Integer.MIN_VALUE; max = Integer.MAX_VALUE; } minvärde = min; maxvärde = max; startvärde = start; } public void addera() { startvärde += 1; } public void subtrahera() { startvärde -= 1; } }
- 02-05-2013, 03:19 PM #2
Re: Trying to learn methods.
That's not an error. That's a String representation of an Object that has not overridden the toString() method. Think about it this way: how does Java know how to display an Object as a String? It doesn't, unless you tell it how to by overriding the toString() method.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 02-05-2013, 03:45 PM #3
Re: Trying to learn methods.
int minvärde,maxvärde,startvärde;
And never ever use Umlauts in java code!Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 02-05-2013, 04:24 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
- 02-05-2013, 04:30 PM #5
Re: Trying to learn methods.
I've have heard reports about strange effects. It's generally advised here in Germany not to do it. Something about different default system encodings on servers and developer systems, if I recall corretly.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 02-05-2013, 04:50 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Trying to learn methods.
System encodings should have no effect on variables in Java code, as it should all be UTF.
I can see something when dealing with Strings that contain non-ASCII, but that's character encoding and nothing to do with Java and the compiler.Please do not ask for code as refusal often offends.
- 02-05-2013, 06:06 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Re: Trying to learn methods.
I prefer a random combination of Cyrilic, Chinese and Arabic characters (and umlauts) just to poke fun at those ASCII-centric pommies and for obfuscation reasons ...
kind regards,
乔斯When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-05-2013, 06:20 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Trying to learn methods.
I would laugh if it turns out that means something rude...
Sadly you managed to spell Jos, unless Google translate is pulling a fast one.
I live in hope.Please do not ask for code as refusal often offends.
- 02-05-2013, 07:24 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 02-06-2013, 02:05 PM #10
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Re: Trying to learn methods.
- 02-06-2013, 02:16 PM #11
Re: Trying to learn methods.
Did that work?
I wouldn't say it's the only solution. You could have written another method and called that, or created a method that takes a calc (which should be Calc, by the way) Object and returns a String, or... the options are endless. But since you were already calling the toString() method, it does make sense to specify what that method should do.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
Why and where abstract methods & classes and static methods used?
By ajaysharma in forum New To JavaReplies: 1Last Post: 07-12-2012, 11:04 PM -
Trouble with static methods and boolean equals() methods with classes
By dreamingofgreen in forum New To JavaReplies: 8Last Post: 04-16-2012, 11:00 PM -
Java Noob, trying to call methods from another methods
By gabrielpr12 in forum New To JavaReplies: 8Last Post: 11-17-2011, 09:07 PM -
difference between static methods and instantce methods?
By venkatch in forum New To JavaReplies: 1Last Post: 10-23-2011, 12:37 PM -
Incorporating If-Else into Methods + Private Helper Methods?
By 5minutes in forum New To JavaReplies: 1Last Post: 10-05-2011, 12:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks