mihainan

Ex 5 a) - Lab POO

Oct 28th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package Lab04;
  2.  
  3. import java.util.Hashtable;
  4.  
  5. /**
  6.  *
  7.  * @author Nan Mihai
  8.  */
  9. public class HSet extends Hashtable{
  10.    
  11.     public void add(Object o) {
  12.         super.put(o, o);
  13.     }
  14.    
  15.     @Override
  16.     public boolean contains(Object o) {
  17.         return super.contains(o);
  18.     }
  19.    
  20.     public int size() {
  21.         return super.size();
  22.     }
  23.    
  24.     public String toString() {
  25.         return super.toString();
  26.     }
  27.    
  28.     public void afisare(int x) {
  29.         boolean ok;
  30.         ok = this.contains(x);
  31.         if(ok) {
  32.             System.out.println("Elementul " + x + " se afla in HSet!");
  33.         } else {
  34.             System.out.println("Elementul " + x + " nu se afla in HSet!");
  35.         }
  36.     }
  37.    
  38.     public static void main( String args[] ) {
  39.         boolean ok;
  40.         int x;
  41.         x = 0;
  42.         HSet M = new HSet();
  43.         for(int i = 0; i < 100; i++) {
  44.             x = (int) Math.round(Math.random()*1000);
  45.             M.add(x);
  46.         }
  47.         System.out.println(M);
  48.         M.afisare(x);
  49.         M.afisare(158);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment