Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. import java.util.List;
  2.  
  3. public class Centrala {
  4. private Regał[] regały;
  5. int max_regał, max_półka, max_slot; // numerowane od 0 do max-1;
  6.  
  7. public Centrala(int ile_regałów, int ile_półek, int ile_slotów) {
  8. regały = new Regał[ile_regałów];
  9. for (int i = 0; i < ile_regałów; i++) {
  10. regały[i] = new Regał(ile_półek, ile_slotów);
  11. }
  12. }
  13.  
  14. public boolean WstawModuł(Slot slot, Moduł moduł) { // zwraca false gdy slot jest zajęty
  15. return slot.WstawModuł(moduł);
  16. }
  17.  
  18. public void UsuńModuł(Slot slot) {
  19. slot.UsuńModuł();
  20. }
  21.  
  22. public void WłączModuł(Moduł moduł) {
  23. moduł.Włącz();
  24. }
  25.  
  26. public void WyłączModuł(Moduł moduł) {
  27. moduł.Wyłącz();
  28. }
  29.  
  30. public void WypiszTyp(int typ) {
  31. for (int i = 0; i < max_regał; i++) {
  32. for (int j = 0; j < max_półka; j++) {
  33. for (int k = 0; k < max_slot; k++) {
  34. Slot s = GetSlot(i,j,k);
  35. if(s.GetModuł().GetTyp() == typ) {
  36. System.out.println(s.GetModuł().ToString());
  37. }
  38. }
  39. }
  40. }
  41. }
  42.  
  43. public void WypiszCentrala() {
  44. for (int i = 0; i < max_regał; i++) {
  45. for (int j = 0; j < max_półka; j++) {
  46. for (int k = 0; k < max_slot; k++) {
  47. Slot s = GetSlot(i,j,k);
  48. System.out.println(s.GetModuł().ToString());
  49. }
  50. }
  51. }
  52. }
  53.  
  54. public void WypiszRegał(int regał) {
  55. for (int i = 0; i < max_regał; i++) {
  56. for (int j = 0; j < max_półka; j++) {
  57. for (int k = 0; k < max_slot; k++) {
  58. Slot s = GetSlot(i,j,k);
  59. if(i == regał) {
  60. System.out.println(s.GetModuł().ToString());
  61. }
  62. }
  63. }
  64. }
  65. }
  66.  
  67. public void WypiszPółkę(int regał, int półka) {
  68. for (int i = 0; i < max_regał; i++) {
  69. for (int j = 0; j < max_półka; j++) {
  70. for (int k = 0; k < max_slot; k++) {
  71. Slot s = GetSlot(i,j,k);
  72. if(i == regał && j == półka) {
  73. System.out.println(s.GetModuł().ToString());
  74. }
  75. }
  76. }
  77. }
  78. }
  79.  
  80. public Slot GetSlot(int regał, int półka, int slot) {
  81. if (regał >= max_regał) {
  82. return null;
  83. }
  84.  
  85. if (półka >= max_półka) {
  86. return null;
  87. }
  88.  
  89. if (slot >= max_slot) {
  90. return null;
  91. }
  92.  
  93. return regały[regał].GetPółka(półka).GetSlot(slot);
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement