GieeF

Untitled

May 4th, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import java.rmi.AlreadyBoundException;
  2. import java.util.Arrays;
  3. import java.util.Collections;
  4.  
  5. import javax.naming.SizeLimitExceededException;
  6.  
  7. public class Zad2 {
  8.  
  9. }
  10.  
  11. class Kwadrat implements Comparable<Kwadrat> {
  12. private int bok;
  13.  
  14. Kwadrat(int bok) {
  15. this.bok = bok;
  16. }
  17.  
  18. int getBok() {
  19. return this.bok;
  20. }
  21.  
  22. @Override
  23. public int compareTo(Kwadrat k) {
  24. // TODO Auto-generated method stub
  25. return this.getBok().equals(k.getBok());
  26. }
  27. }
  28.  
  29. class Biblioteczka implements Comparable<Biblioteczka> {
  30. private int iloscKsiazek;
  31.  
  32. Biblioteczka(int iloscKsiazek) {
  33. this.iloscKsiazek = iloscKsiazek;
  34. }
  35.  
  36. int getIlosc() {
  37. return this.iloscKsiazek;
  38. }
  39.  
  40. @Override
  41. public int compareTo(Biblioteczka b) {
  42. return ;
  43. }
  44. }
  45.  
  46. class Set<T> implements Comparable<T>{
  47. T [] set;
  48. int pojemnosc;
  49. int rozmiar;
  50.  
  51. @SuppressWarnings("unchecked")
  52. Set(int pojemnosc) {
  53. this.pojemnosc = pojemnosc;
  54. set = (T[]) new Set[pojemnosc];
  55. }
  56.  
  57. @SuppressWarnings("unchecked")
  58. void dodajElement(T elem) throws AlreadyBoundException, SizeLimitExceededException{
  59. for(int i = 0; i < rozmiar; i++) {
  60. if(((Comparable<T>) set[i]).compareTo(elem) != -1) {
  61. throw new IllegalArgumentException("Wartosc znajduje sie w tablicy");
  62. }
  63. }
  64. if(rozmiar == pojemnosc) {
  65. throw new SizeLimitExceededException();
  66. }
  67.  
  68. set[rozmiar] = elem;
  69. rozmiar++;
  70.  
  71. Arrays.sort(set);
  72. }
  73.  
  74. void szukaj(T elem) {
  75. for(int i = 0; i < rozmiar; i++) {
  76.  
  77. }
  78. }
  79.  
  80. public String toString() {
  81. String result = "";
  82.  
  83. result += "Rozmiar: " + rozmiar;
  84. result += "\nPojemnosc: " + pojemnosc;
  85. result += "\nLista elementow:";
  86.  
  87. for(int i = 0; i < rozmiar; i++) {
  88. result += set[i] + " ";
  89. }
  90.  
  91. return result;
  92. }
  93.  
  94. @Override
  95. public int compareTo(T o) {
  96. // TODO Auto-generated method stub
  97. return 0;
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment