Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Cualquierexcepcion extends Exception{
- public Cualquierexcepcion(){}
- public Cualquierexcepcion(String mssg){
- super(mssg);
- }
- }
- //estas son checked exceptions?
- Patter compile p = Pattern.compile("");
- Matcher m = p.matcher(string);
- if(!m.find()){
- throw new CreationException();
- }
- //Main Class extends Comparable
- @Override
- public boolean equals(Object o) {
- if (o instanceof Alumnos) {
- Alumnos p = (Alumnos)o;
- return this.name.equals(p.name);
- } else
- return false;
- }
- @Override
- public int hashCode() {
- return age * this.name.length();
- }
- @Override
- public int compareTo(Object t){
- if(t instanceof Student){
- Student s = (Student)t;
- return (this.name.compareTo(s.name));
- }
- else
- return -1;
- }
- //My car Test
- @Before
- public void setUp() throws Exception {
- }
- @Test (expected = LowFuelException.class)
- public void testStartTripFail() throws LowFuelException, CreationException {
- MyCar car6 = new MyCar("45 5 bmw");
- car6.startTrip(1000.0);
- }
- @Test
- public void testGetMileage() throws CreationException {
- MyCar car7 = new MyCar("47 10 Volvo");
- double mil = car7.getMileage();
- assertTrue(mil==0.0);
- //assertFalse(mil!=0.0);
- }
- TreeMap<Integer, String> tmap =
- new TreeMap<Integer, String>();
- tmap.put(1, "Data1");
- /* Display content using Iterator*/
- Set set = tmap.entrySet();
- Iterator iterator = set.iterator();
- while(iterator.hasNext()) {
- Map.Entry mentry = (Map.Entry)iterator.next();
- System.out.print("key is: "+ mentry.getKey() + " & Value is: ");
- System.out.println(mentry.getValue());
- }
- //////////////////////////////////////////
- /* This is how to declare HashMap */
- HashMap<Integer, String> hmap = new HashMap<Integer, String>();
- /*Adding elements to HashMap*/
- hmap.put(12, "Chaitanya");
- /* Display content using Iterator*/
- Set set = hmap.entrySet();
- Iterator iterator = set.iterator();
- while(iterator.hasNext()) {
- Map.Entry mentry = (Map.Entry)iterator.next();
- System.out.print("key is: "+ mentry.getKey() + " & Value is: ");
- System.out.println(mentry.getValue());
- }
- /* Get values based on key*/
- String var= hmap.get(2);
- System.out.println("Value at index 2 is: "+var);
- /* Remove values based on key*/
- hmap.remove(3);
- System.out.println("Map key and values after removal:");
- Set set2 = hmap.entrySet();
- Iterator iterator2 = set2.iterator();
- while(iterator2.hasNext()) {
- Map.Entry mentry2 = (Map.Entry)iterator2.next();
- System.out.print("Key is: "+mentry2.getKey() + " & Value is: ");
- System.out.println(mentry2.getValue());
- }
- ////////////////////////////////////////////
- // HashSet declaration
- HashSet<String> hset =
- new HashSet<String>();
- // Adding elements to the HashSet
- hset.add("Apple");
- //Displaying HashSet elements
- System.out.println(hset);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement