Advertisement
Svetlana_Ovsjanikova

java - Arrays.daudzsturi

Sep 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package day4_classes2;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author sao_7
  13. */
  14. public class Daudzsturi {
  15. private double a, b, c, d;
  16. Scanner sc = new Scanner(System.in);
  17. //1. uztaisit konstruktoru, kas pieskir visiem mainigajiem vertibu 0
  18. public Daudzsturi (){
  19. a = 0;
  20. b = 0;
  21. c = 0;
  22. d = 0;
  23. maluskaits = 0;
  24. }
  25. //2. uztaisit velvienu privato mainiigo, kas atbildes malu skaitu
  26. private int maluskaits = 4;
  27.  
  28. //3. malu skaitam uztaisat set metodi (hint- setA(int number))
  29. public void setMaluSkaits (int number){
  30.  
  31. maluskaits = number;
  32.  
  33. }
  34. //4. set metodi, kas pieskir vertibas mainigajiem a, b, c, d
  35. public void setMalas (double mala1, double mala2, double mala3, double mala4){
  36. a = mala1;
  37. b = mala2;
  38. c = mala3;
  39. d = mala4;
  40. }
  41.  
  42. public void setMalas(double mala1, double mala2, double mala3){
  43. a = mala1;
  44. b = mala2;
  45. c = mala3;
  46. }
  47. //5. uztaisit metodi, kas aprekina perimetru un ar return atgriez vertibu
  48. public double getPerimetrs(){
  49. switch(maluskaits){
  50. case 3:
  51. return a + b + c;
  52. case 4:
  53. return a + b + c + d;
  54. default:
  55. return 0;
  56. }
  57.  
  58. }
  59. //obligati jabut pozitiviem skaitliem- a, b, c un d obligati nav
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement