Untitled

 avatar
unknown
java
2 years ago
1.4 kB
4
Indexable
import java.io.*;
import java.util.*;

class Business {
    int netWorth;
    int nseValue;

    Business(int netWorth, int nseValue) {
        this.netWorth = netWorth;
        this.nseValue = nseValue;
    }
}

class Validator {
    public String billionWorth(Business business) throws Exception {
        if (business.netWorth < 50) {
            throw new BusinessException("Not to be recommend");
        }

        if (business.nseValue < 0) {
            throw new BusinessException("Company under loss");
        }

        return "Recommend";
    }

    public String recommendPartner(Business business) throws Exception {
        try {
            billionWorth(business);
        }
        catch (BusinessException exp) {
            return "Not recommend";
        }
        catch (Exception exp) {
            return "Other exception";
        }

        return "Parternship availed";
    }
}

class BusinessException extends Exception {
    public BusinessException(String msg) {
        System.out.println(msg);
    }
}


public class Source1 {
    public static void main(String args[]) throws Exception {
        Business business = new Business(67, 7);
        Validator v = new Validator();
        String s = v.billionWorth(business);
        String t = v.recommendPartner(business);

        System.out.println(s);
        System.out.println(t);
    }
}
Editor is loading...