Advertisement
Sylv3rWolf

lab2

Oct 12th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. package Zbior;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. /**
  7. *
  8. * @author MaxSylverWolf
  9. */
  10. public class Zbiory implements IZbior{
  11.  
  12.  
  13. public int[] tab = new int[100];
  14. public int licznik = 0;
  15.  
  16. public void dodaj(int nowy) {
  17. tab[licznik++] = nowy;
  18. }
  19.  
  20. public void wypisz() {
  21. for(int i=0; i<100; i++)
  22.  
  23. System.out.println("["+tab[i]+"]");
  24.  
  25.  
  26. }
  27.  
  28. static Scanner skanuj = new Scanner(System.in);
  29. static Random losuj = new Random();
  30.  
  31. public static void main(String[] args) {
  32.  
  33. Zbiory zbior = new Zbiory();
  34.  
  35. System.out.println("Podaj ilość elementów w tablicy: ");
  36. int n;
  37. n = skanuj.nextInt();
  38.  
  39. int[] tablica = new int[n];
  40. System.out.println("Podaj je");
  41.  
  42.  
  43. for(int i=0;i<n;i++) {
  44.  
  45. tablica[i] = skanuj.nextInt();
  46. }
  47. System.out.println("");
  48.  
  49. wypisz();
  50.  
  51. System.out.println("Co chcesz zrobić?");
  52.  
  53.  
  54. System.out.println("1 - Dodaj element do tablicy");
  55. System.out.println("2 - Usuń element z tablicy");
  56. System.out.println("3 - Zwróc rozmiar tablicy");
  57. System.out.println("4 - Sprawdź czy zawiera podany element");
  58. System.out.println("5 - Wypisz tablice");
  59. int licznik = skanuj.nextInt();
  60. switch(licznik) {
  61.  
  62. case 1: {
  63.  
  64. System.out.println("Wprowadź element: ");
  65. int nowy = skanuj.nextInt();
  66. tablica[n++] = nowy;
  67. } break;
  68. case 2: {
  69.  
  70. System.out.println("Który element chcesz usunąć? Podaj tą liczbę");
  71. int element = skanuj.nextInt();
  72. for(int i=0;i<n;i++) {
  73. if(tablica[i]==element) {
  74. tablica[i]=tablica[n];
  75. n--; } } } break;
  76.  
  77. case 3: {
  78.  
  79. System.out.println("Rozmiar tablicy to: "+n--);
  80.  
  81. } break;
  82.  
  83. case 4: {
  84.  
  85. System.out.println("Podaj element, który chcesz sprawdzić czy istnieje: ");
  86. int sprawdz = skanuj.nextInt();
  87. for(int i =0 ; i<n;i++){
  88. if(sprawdz==tablica[i])System.out.println("Zawiera ten element");
  89. else System.out.println("Nie zawiera tego elementu");
  90. }
  91. } break;
  92.  
  93. case 5: System.out.println(tablica); break;
  94. }
  95.  
  96. skanuj.close();
  97.  
  98. }
  99.  
  100. @Override
  101. public void usun(int element) {
  102. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  103. }
  104.  
  105. @Override
  106. public int rozmiar() {
  107. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  108. }
  109.  
  110. @Override
  111. public boolean czyZawiera(int element) {
  112. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  113. }
  114.  
  115. @Override
  116. public void wczytaj(String filename) {
  117. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  118. }
  119.  
  120. @Override
  121. public boolean czyRowne(IZbior drugi) {
  122. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  123. }
  124.  
  125. @Override
  126. public IZbior suma(IZbior drugi) {
  127. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  128. }
  129.  
  130. @Override
  131. public IZbior roznica(IZbior drugi) {
  132. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  133. }
  134.  
  135. @Override
  136. public IZbior przeciecie(IZbior drugi) {
  137. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  138. }
  139.  
  140. @Override
  141. public IZbior roznicaSymetryczna(IZbior drugi) {
  142. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  143. }
  144.  
  145.  
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement