Created
May 30, 2016 10:50
-
-
Save DinisCruz/b793d581bd487da20254bd54a5ffb54f to your computer and use it in GitHub Desktop.
Elegant Objects code snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//executed in https://www.compilejava.net/ | |
public class CashTest | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.println(new Cash(12).Value()); | |
System.out.println(new Cash("12").Value()); | |
// System.out.println(new Cash("12.12f").Value()); // doesn't work and throws exception | |
System.out.println(new Cash(12.12f).Value()); | |
} | |
} | |
public class Cash | |
{ | |
private int dollars; | |
Cash(float dlr) | |
{ | |
this((int) dlr); | |
} | |
Cash(String dlr) | |
{ | |
this.dollars = Integer.parseInt(dlr); | |
} | |
Cash(int dlr) | |
{ | |
this.dollars = dlr; | |
} | |
public int Value() | |
{ | |
return this.dollars; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment