Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. ////Figury\\\\\
  2.  
  3. package javaapplication2;
  4.  
  5. public abstract class Figury {
  6.  
  7. protected double a;
  8. protected String typ;
  9. protected double obwod, pole;
  10.  
  11.  
  12. public Figury(String typ)
  13. {
  14. this.typ=typ;
  15.  
  16. }
  17.  
  18. abstract String KlasaFigury();
  19. abstract double Obwod();
  20. abstract double Pole();
  21. abstract void Wyswietl();
  22. }
  23.  
  24. ////Okrag\\\\
  25.  
  26.  
  27. package javaapplication2;
  28.  
  29. public class Okrag extends Figury{
  30.  
  31. private double r;
  32.  
  33. public Okrag(String typ, double r)throws NiepoprawneDane
  34. {
  35. super(typ);
  36. if(r<=0)
  37. throw new NiepoprawneDane();
  38. else
  39. this.r=r;
  40.  
  41. }
  42.  
  43.  
  44. String KlasaFigury() {
  45. return typ;
  46. }
  47.  
  48.  
  49. public double Obwod() {
  50. obwod = 6.28*r;
  51. return obwod;
  52.  
  53. }
  54.  
  55.  
  56. public double Pole() {
  57. pole = r*r*3.14;
  58. return pole;
  59.  
  60. }
  61.  
  62. void Wyswietl() {
  63. System.out.print("Figura: " +KlasaFigury() + "\n");
  64. System.out.print("Pole: " +Pole() + "\n");
  65. System.out.print("Obwod: " + Obwod() + "\n");
  66.  
  67. }
  68.  
  69. }
  70.  
  71. ////Trojkat\\\\
  72.  
  73. package javaapplication2;
  74.  
  75.  
  76. public class Trojkat extends Figury{
  77.  
  78. private double b, c;
  79.  
  80. public Trojkat(String typ, double a, double b, double c)throws NiepoprawneDane
  81. {
  82. super(typ);
  83. if(a<=0 || b<=0 || c<=0 || a+b<c || b+c<a || a+c<b)
  84. throw new NiepoprawneDane();
  85. else
  86. this.a=a;
  87. this.b=b;
  88. this.c=c;
  89. }
  90.  
  91.  
  92. String KlasaFigury() {
  93. return typ;
  94. }
  95.  
  96.  
  97. public double Obwod() {
  98. obwod = a+b+c;
  99. return obwod;
  100.  
  101. }
  102.  
  103.  
  104. public double Pole() {
  105. pole = 0.5*(a+b+c);
  106. return pole;
  107.  
  108. }
  109.  
  110. void Wyswietl() {
  111.  
  112. System.out.print("Figura: " +KlasaFigury() + "\n");
  113. System.out.print("Pole: " +Pole() + "\n");
  114. System.out.print("Obwod: " + Obwod() + "\n");
  115. }
  116.  
  117.  
  118. }
  119.  
  120. ////Prostokat\\\\\
  121.  
  122. package javaapplication2;
  123.  
  124.  
  125. public class Prostokat extends Figury {
  126.  
  127. private double b;
  128.  
  129. public Prostokat(String typ, double a, double b)throws NiepoprawneDane
  130. {
  131. super(typ);
  132. if(a<=0 || b<=0)
  133. throw new NiepoprawneDane();
  134. else
  135. this.a=a;
  136. this.b=b;
  137.  
  138. }
  139.  
  140. String KlasaFigury() {
  141. return typ;
  142. }
  143.  
  144.  
  145. public double Obwod() {
  146. obwod = 2*a+2*b;
  147. return obwod;
  148.  
  149. }
  150.  
  151.  
  152. public double Pole() {
  153. pole = a*b;
  154. return pole;
  155.  
  156. }
  157.  
  158. void Wyswietl() {
  159. System.out.print("Figura: " +KlasaFigury() + "\n");
  160. System.out.print("Pole: " +Pole() + "\n");
  161. System.out.print("Obwod: " + Obwod() + "\n");
  162.  
  163. }
  164.  
  165.  
  166. }
  167.  
  168.  
  169. /////Grupa\\\\\
  170.  
  171. package javaapplication2;
  172.  
  173. public class Grupa{
  174.  
  175. private String[] Tab;
  176. private int n;
  177.  
  178. public Grupa(int n)
  179. {
  180. this.n=n;
  181. }
  182.  
  183.  
  184. String KlasaFigury() {
  185. throw new UnsupportedOperationException("Not supported yet.");
  186. }
  187.  
  188.  
  189. double Obwod() {
  190. throw new UnsupportedOperationException("Not supported yet.");
  191. }
  192.  
  193.  
  194. double Pole() {
  195. throw new UnsupportedOperationException("Not supported yet.");
  196. }
  197.  
  198.  
  199. void Wyswietl() {
  200. throw new UnsupportedOperationException("Not supported yet.");
  201. }
  202.  
  203. }
  204.  
  205.  
  206. ////NiepoprawneDane\\\\\
  207.  
  208.  
  209. package javaapplication2;
  210.  
  211. public class NiepoprawneDane extends Exception {
  212.  
  213.  
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement