SHARE
TWEET

PoleProstokataException

Mereti Apr 18th, 2019 (edited) 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //-----MAIN----------------------------------------------------------------------------------------------------------------------------
  2. package com.company;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Obliczzenia poleProstokata = new Obliczzenia(-1, 2);
  9.         try {
  10.             System.out.println("Pole prostokata wynosi : " + poleProstokata.wynik1());
  11.         } catch (NieprawidloweDaneException e) {
  12.             System.out.println("Nieprawidlowe dane.");
  13.         }
  14.     }
  15. }
  16. //-----Obliczzenia---------------------------------------------------------------------------------------------------------------------
  17. package com.company;
  18. //Napisz program, który oblicza pole prostokata. Wartoci boków
  19. //a i b wprowadzamy z klawiatury. W programie nalezy przyjac,
  20. //ze zmienne a, b oraz pole s typu double (rzeczywistego).
  21.  
  22. public class Obliczzenia {
  23.  
  24.     private double bok1;
  25.     private double bok2;
  26.  
  27.     public Obliczzenia(double a , double b){
  28.         this.bok1 = a;
  29.         this.bok2 = b;
  30.     }
  31.  
  32.     public double wynik1()throws NieprawidloweDaneException{
  33.         if(bok1 < 0 || bok2 < 0){
  34.             throw new NieprawidloweDaneException();
  35.         }
  36.             double wynik = bok1 * bok2;
  37.         return wynik;
  38.     }
  39. }
  40. //----NieprawidloweDaneException-------------------------------------------------------------------------------------------------------
  41. package com.company;
  42.  
  43. public class NieprawidloweDaneException extends Throwable {
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top