Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class IllegalCoinSideException extends RuntimeException{
- private static final long serialVersionUID = -2225459441999368571L;
- IllegalCoinSideException(){};
- }
- public class Coin extends Throwable{
- private static final long serialVersionUID = 3630805023927806932L;
- boolean heads = false;
- Coin(){
- double chans = Math.random() * 100.0;
- if(chans > 50){
- heads = true;
- }else if(chans < 50){
- heads = false;
- }else{
- throw new IllegalCoinSideException();
- }
- }
- @Override
- public String toString(){
- return heads ? "Heads" : "Tails";
- }
- public static void main(String[] args){
- try{
- throw new Coin();
- }catch(Coin c){
- System.out.println(c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement