SHARE
TWEET

Untitled

a guest Jan 24th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Cualquierexcepcion extends Exception{
  2.     public Cualquierexcepcion(){}
  3.     public Cualquierexcepcion(String mssg){
  4.         super(mssg);
  5.     }
  6. }
  7. //estas son checked exceptions?
  8.  
  9. Patter compile p = Pattern.compile("");
  10. Matcher m = p.matcher(string);
  11. if(!m.find()){
  12.     throw new CreationException();
  13. }
  14.  
  15.     //Main Class extends Comparable
  16.     @Override
  17.     public boolean equals(Object o) {
  18.         if (o instanceof Alumnos) {
  19.             Alumnos p = (Alumnos)o;
  20.             return this.name.equals(p.name);
  21.         } else
  22.             return false;
  23.     }
  24.  
  25.     @Override
  26.     public int hashCode() {
  27.      return age * this.name.length();
  28.     }
  29.  
  30.     @Override
  31.     public int compareTo(Object t){
  32.         if(t instanceof Student){
  33.             Student s = (Student)t;
  34.             return (this.name.compareTo(s.name));
  35.         }
  36.     else
  37.         return -1;
  38.     }
  39.  
  40.     //My car Test
  41.     @Before
  42.     public void setUp() throws Exception {
  43.     }
  44.     @Test (expected = LowFuelException.class)
  45.     public void testStartTripFail() throws LowFuelException, CreationException {
  46.         MyCar car6 = new MyCar("45 5 bmw");
  47.         car6.startTrip(1000.0);
  48.     }
  49.     @Test
  50.     public void testGetMileage() throws CreationException {
  51.         MyCar car7 = new MyCar("47 10 Volvo");
  52.         double mil = car7.getMileage();
  53.         assertTrue(mil==0.0);
  54.         //assertFalse(mil!=0.0);
  55.     }
  56.  
  57.     TreeMap<Integer, String> tmap =
  58.     new TreeMap<Integer, String>();
  59.     tmap.put(1, "Data1");
  60.  
  61.     /* Display content using Iterator*/
  62.       Set set = tmap.entrySet();
  63.       Iterator iterator = set.iterator();
  64.       while(iterator.hasNext()) {
  65.          Map.Entry mentry = (Map.Entry)iterator.next();
  66.          System.out.print("key is: "+ mentry.getKey() + " & Value is: ");
  67.          System.out.println(mentry.getValue());
  68.       }
  69.  
  70. //////////////////////////////////////////
  71.       /* This is how to declare HashMap */
  72.       HashMap<Integer, String> hmap = new HashMap<Integer, String>();
  73.  
  74.       /*Adding elements to HashMap*/
  75.       hmap.put(12, "Chaitanya");
  76.  
  77.       /* Display content using Iterator*/
  78.       Set set = hmap.entrySet();
  79.       Iterator iterator = set.iterator();
  80.       while(iterator.hasNext()) {
  81.          Map.Entry mentry = (Map.Entry)iterator.next();
  82.          System.out.print("key is: "+ mentry.getKey() + " & Value is: ");
  83.          System.out.println(mentry.getValue());
  84.       }
  85.  
  86.       /* Get values based on key*/
  87.       String var= hmap.get(2);
  88.       System.out.println("Value at index 2 is: "+var);
  89.  
  90.       /* Remove values based on key*/
  91.       hmap.remove(3);
  92.       System.out.println("Map key and values after removal:");
  93.       Set set2 = hmap.entrySet();
  94.       Iterator iterator2 = set2.iterator();
  95.       while(iterator2.hasNext()) {
  96.           Map.Entry mentry2 = (Map.Entry)iterator2.next();
  97.           System.out.print("Key is: "+mentry2.getKey() + " & Value is: ");
  98.           System.out.println(mentry2.getValue());
  99.        }
  100. ////////////////////////////////////////////
  101.  // HashSet declaration
  102.       HashSet<String> hset =
  103.                new HashSet<String>();
  104.  
  105.       // Adding elements to the HashSet
  106.       hset.add("Apple");
  107.       //Displaying HashSet elements
  108.       System.out.println(hset);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top