Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 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 figury.zad6;
  7. import java.util.LinkedList;
  8. /**
  9. *
  10. * @author bomba
  11. */
  12. public class Obraz {
  13. private final LinkedList<Trójkąt> TroList = new LinkedList<>();
  14. private final LinkedList<Czworokąt> CzoList = new LinkedList<>();
  15.  
  16. public void dodajCzworokąt(Czworokąt ABCD){
  17. CzoList.add(ABCD);
  18. }
  19.  
  20. public void dodajTrójkąt(Trójkąt ABC){
  21. TroList.add(ABC);
  22. }
  23.  
  24. public void wypiszCzworokąt(int index){
  25. try{
  26. Czworokąt ABCD = CzoList.get(index);
  27. System.out.println(ABCD);
  28. }
  29. catch(IndexOutOfBoundsException e){
  30. System.out.println("Czworokąt z podanym indexem nie istnieje");
  31. }
  32.  
  33. }
  34.  
  35. public void wypiszTrójkąt(int index){
  36. try{
  37. Trójkąt ABC = TroList.get(index);
  38. System.out.println(ABC);
  39. }
  40. catch(IndexOutOfBoundsException e){
  41. System.out.println("Trójkąt z podanym indexem nie istnieje");
  42. }
  43. }
  44.  
  45. public void przesunCzworokąt(int dx, int dy, int index){
  46. try{
  47. Czworokąt ABCD = CzoList.get(index);
  48. ABCD.przesun(dx, dy);
  49. CzoList.remove(index);
  50. CzoList.add(index, ABCD);
  51. }
  52. catch(IndexOutOfBoundsException e){
  53. System.out.println("Czworokąt o podanym indexie nie istnieje");
  54. }
  55. }
  56.  
  57. public void przesunTrójkąt(int dx, int dy, int index){
  58. try{
  59. Trójkąt ABC = TroList.get(index);
  60. ABC.przesun(dx, dy);
  61. TroList.remove(index);
  62. TroList.add(index, ABC);
  63. }
  64. catch(IndexOutOfBoundsException e){
  65. System.out.println("Trójkąt o podanym indexie nie istnieje");
  66. }
  67. }
  68.  
  69. public void przesunWszystkieCzworokąty(int dx, int dy){
  70. for(int i=0; i<CzoList.size(); i++){
  71. Czworokąt ABCD = CzoList.get(i);
  72. ABCD.przesun(dx, dy);
  73. CzoList.remove(i);
  74. CzoList.add(i, ABCD);
  75. }
  76. }
  77.  
  78. public void przesunWszystkieTrójkąty(int dx, int dy){
  79. for(int i=0; i<TroList.size(); i++){
  80. Trójkąt ABC = TroList.get(i);
  81. ABC.przesun(dx, dy);
  82. TroList.remove(i);
  83. TroList.add(i, ABC);
  84. }
  85. }
  86.  
  87. public void wypiszWszystkieCzworokąty(){
  88. if(!CzoList.isEmpty())
  89. for(int i=0; i<CzoList.size(); i++) System.out.println(CzoList.get(i));
  90. else System.out.println("Lista jest pusta");
  91. }
  92.  
  93. public void wypiszWszystkieTrójkąty(){
  94. if(!TroList.isEmpty())
  95. for(int i=0; i<TroList.size(); i++) System.out.println(TroList.get(i));
  96. else System.out.println("Lista jest pusta");
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement