Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.rmi.AlreadyBoundException;
- import java.util.Arrays;
- import java.util.Collections;
- import javax.naming.SizeLimitExceededException;
- public class Zad2 {
- }
- class Kwadrat implements Comparable<Kwadrat> {
- private int bok;
- Kwadrat(int bok) {
- this.bok = bok;
- }
- int getBok() {
- return this.bok;
- }
- @Override
- public int compareTo(Kwadrat k) {
- // TODO Auto-generated method stub
- return this.getBok().equals(k.getBok());
- }
- }
- class Biblioteczka implements Comparable<Biblioteczka> {
- private int iloscKsiazek;
- Biblioteczka(int iloscKsiazek) {
- this.iloscKsiazek = iloscKsiazek;
- }
- int getIlosc() {
- return this.iloscKsiazek;
- }
- @Override
- public int compareTo(Biblioteczka b) {
- return ;
- }
- }
- class Set<T> implements Comparable<T>{
- T [] set;
- int pojemnosc;
- int rozmiar;
- @SuppressWarnings("unchecked")
- Set(int pojemnosc) {
- this.pojemnosc = pojemnosc;
- set = (T[]) new Set[pojemnosc];
- }
- @SuppressWarnings("unchecked")
- void dodajElement(T elem) throws AlreadyBoundException, SizeLimitExceededException{
- for(int i = 0; i < rozmiar; i++) {
- if(((Comparable<T>) set[i]).compareTo(elem) != -1) {
- throw new IllegalArgumentException("Wartosc znajduje sie w tablicy");
- }
- }
- if(rozmiar == pojemnosc) {
- throw new SizeLimitExceededException();
- }
- set[rozmiar] = elem;
- rozmiar++;
- Arrays.sort(set);
- }
- void szukaj(T elem) {
- for(int i = 0; i < rozmiar; i++) {
- }
- }
- public String toString() {
- String result = "";
- result += "Rozmiar: " + rozmiar;
- result += "\nPojemnosc: " + pojemnosc;
- result += "\nLista elementow:";
- for(int i = 0; i < rozmiar; i++) {
- result += set[i] + " ";
- }
- return result;
- }
- @Override
- public int compareTo(T o) {
- // TODO Auto-generated method stub
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment