Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1.  
  2. package oop2a;
  3.  
  4. import java.util.Scanner;
  5.  
  6. class Kwadrat
  7. {
  8. public Kwadrat()
  9. {
  10. bok = 0;
  11. }
  12.  
  13. public Kwadrat( double bok )
  14. {
  15. ustawBok( bok );
  16. }
  17.  
  18. public void ustawBok( double bok )
  19. {
  20. if( bok >= 0 )
  21. this.bok = bok;
  22. }
  23. public double podajBok()
  24. {
  25. return bok;
  26. }
  27. public double pole()
  28. {
  29. return bok * bok;
  30. }
  31.  
  32. protected double bok;
  33. }
  34.  
  35. class Szescian extends Kwadrat
  36. {
  37. public Szescian()
  38. {
  39. super();
  40. }
  41. public Szescian( double bok )
  42. {
  43. super( bok );
  44. }
  45. @Override
  46. public double pole()
  47. {
  48. return 6 * super.pole();
  49. }
  50. }
  51.  
  52. public class OOP2a
  53. {
  54. public static void main(String[] args)
  55. {
  56. Scanner we = new Scanner( System.in );
  57. double bok;
  58.  
  59. System.out.print( "Podaj długość boku: " );
  60. bok = we.nextDouble();
  61.  
  62. Szescian k = new Szescian( bok );
  63.  
  64. //k.ustawBok( bok );
  65.  
  66. System.out.println( "Pole: " + k.pole() );
  67.  
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement