Advertisement
mmouhib

Untitled

Feb 21st, 2022
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.  
  2. package com.company;
  3.  
  4. import java.lang.Exception;
  5.  
  6. class CustomException extends Exception{
  7.     public CustomException(String err){
  8.         super(err);
  9.     }
  10. }
  11.  
  12. class Equation {
  13.     float a, b = 0;
  14.     public  Equation(float a, float b) {
  15.         this.a = a;
  16.         this.b = b;
  17.     }
  18.  
  19.     public float Resolve() throws CustomException{
  20.         if (a == 0 && b == 0){
  21.             throw (new CustomException("solution tout R"));
  22.         }
  23.         else if (a == 0 || b == 0){
  24.             throw (new CustomException("impossible"));
  25.         }
  26.         else{
  27.             return (-(b/a));
  28.         }
  29.  
  30.     }
  31. }
  32.  
  33. public class Main {
  34.  
  35.     public static void main(String[] args) throws CustomException {
  36.         Equation eq = new Equation(0,0);
  37.         System.out.println(eq.Resolve());
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement