The solution I had in mind is,
package com.twister; public class Area { //should initialize to 0 - formula mentioned for documentation int area = this.length*this.breath; //Instance variables get initialized to 0 int length = 10; int breath = 20; public static void main(String[] args) { Area a = new Area(); //Do whatever needs to be done in main } }
I find this solution pretty suitable for this problem for a couple of reasons:
1. It does not destroy the essence of the code – the variable area remains part of the class Area which makes the code look logical. The other solution that does the same is making area a method.
2. It goes with the comment of keeping the code self documenting which getting the code to compile.
Of course some of the other solutions are pretty neat too – It's just that I am a little biased towards this one!!
@Matthieu – I missed giving you points for your solution last time – thats corrected now.
@Simonz – You solution (for puzzle 50) is correct too – It satisfies all the rules of puzzle 50.
@Yauheni – Welcome back - : ) – I wish I get my next vacation soon!
FYI: Since you added the separate window for the code it is presented a one line in Google reader. Might turn away people - this is how I originally found the blog.
ReplyDeleteOtherwise I like the blog and keep'em coming.