Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. package shape;
  2.  
  3. public abstract class Shape {
  4. abstract public double getArea();
  5. }
  6.  
  7.  
  8. package shape;
  9.  
  10. public class Rectangle extends Shape{
  11.  
  12. private double a;
  13. private double b;
  14.  
  15. public double getA() {
  16. return a;
  17. }
  18. public void setA(double a) {
  19. this.a = a;
  20. }
  21. public double getB() {
  22. return b;
  23. }
  24. public void setB(double b) {
  25. this.b = b;
  26. }
  27. public Rectangle(double a, double b) {
  28. super();
  29. this.a = a;
  30. this.b = b;
  31. }
  32. @Override
  33. public double getArea() {
  34. return a * b;
  35. }
  36. }
  37.  
  38.  
  39. package shape;
  40.  
  41. public class Triangle extends Shape{
  42. private double c;
  43. private double d;
  44. @Override
  45. public double getArea() {
  46. return c * d * 0.5;
  47. }
  48. public double getC() {
  49. return c;
  50. }
  51. public void setC(double c) {
  52. this.c = c;
  53. }
  54. public double getD() {
  55. return d;
  56. }
  57. public void setD(double d) {
  58. this.d = d;
  59. }
  60. public Triangle(double c, double d) {
  61. super();
  62. this.c = c;
  63. this.d = d;
  64. }
  65.  
  66. }
  67.  
  68.  
  69. package shape;
  70.  
  71. import java.util.Scanner;
  72.  
  73. public class Main {
  74.  
  75. public static void main(String[] args) {
  76. Scanner scn = new Scanner(System.in);
  77. System.out.println("Введіть довжини прямокутника");
  78. double a = scn.nextDouble();
  79. double b = scn.nextDouble();
  80. System.out.println("Площа прямокутника " + new Rectangle(a, b).getArea());
  81. System.out.println("Введіть довжини трикутника");
  82. double c = scn.nextDouble();
  83. double d = scn.nextDouble();
  84. System.out.println("Площа трикутника " + new Triangle(c, d).getArea());
  85. }
  86.  
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement