Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
68
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 interface Shape2 {
  4. public double getArea2();
  5. }
  6.  
  7.  
  8. package shape;
  9.  
  10. public class Rectangle implements Shape2{
  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 getArea2() {
  34.  
  35. return a * b;
  36. }
  37. }
  38.  
  39.  
  40. package shape;
  41.  
  42. public class Triangle implements Shape2{
  43. private double c;
  44. private double d;
  45. @Override
  46. public double getArea2() {
  47. return c * d * 0.5;
  48. }
  49. public double getC() {
  50. return c;
  51. }
  52. public void setC(double c) {
  53. this.c = c;
  54. }
  55. public double getD() {
  56. return d;
  57. }
  58. public void setD(double d) {
  59. this.d = d;
  60. }
  61. public Triangle(double c, double d) {
  62. super();
  63. this.c = c;
  64. this.d = d;
  65. }
  66.  
  67. }
  68.  
  69.  
  70.  
  71. package shape;
  72.  
  73. import java.util.Scanner;
  74.  
  75. public class Main {
  76.  
  77. public static void main(String[] args) {
  78. Scanner scn = new Scanner(System.in);
  79. System.out.println("Введіть довжини прямокутника");
  80. double a = scn.nextDouble();
  81. double b = scn.nextDouble();
  82. System.out.println("Площа прямокутника " + new Rectangle(a, b).getArea2());
  83. System.out.println("Введіть довжини трикутника");
  84. double c = scn.nextDouble();
  85. double d = scn.nextDouble();
  86. System.out.println("Площа трикутника " + new Triangle(c, d).getArea2());
  87. }
  88.  
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement