Categoría: Sin categoría
Implementaciones Set y Map
https://docs.oracle.com/javase/tutorial/collections/implementations/set.html
https://docs.oracle.com/javase/tutorial/collections/implementations/map.html
http://beginnersbook.com/2013/12/hashset-class-in-java-with-example/
http://beginnersbook.com/2013/12/hashmap-in-java-with-example/
Ejemplos excepciones
http://dis.um.es/~bmoros/Tutorial/parte9/cap9-3.html
http://beginnersbook.com/2013/04/java-throws/
Métodos default y estáticos
http://www.genbetadev.com/java-j2ee/java-8-metodos-default
http://codecriticon.com/default-static-interfaces-jdk8/
Archivo Radio
/* * This code is sample code, provided as-is, and we make no * warranties as to its correctness or suitability for * any purpose. * * We hope that it's useful to you. Enjoy. * Copyright 2004-13 LearningPatterns Inc. */ /* * Lab - Interfaces * * This class defines a Radio. It will implement Volume easily * * * This class performs no data validation; however, it * mutes/unmutes appropriately, i.e., can't mute a muted * Radio */ package com.entertainment; // TODO add in declaration for implementing Volume public class Radio { // INSTANCE VARIABLES private int volume; // the volume // for muting behavior private int oldVolume; private boolean isMuted; // CONSTRUCTORS public Radio() { super(); } public Radio(int volumeIn) { super(); this.setVolume(volumeIn); } // ACCESSOR METHODS // from interface Volume public void setVolume(int volumeIn) { // delegate to contained VolumeControl object volume = volumeIn; } /* TODO - Uncomment this method so Radio will compile after implementing the interface // from interface IVolume public int getVolume() { return volume; } */ // from interface IVolume // BEHAVIORAL METHODS public void mute() { if (!this.isMuted()) // not currently muted { // store current volume in oldVolume oldVolume = volume; // set volume to zero this.setVolume(0); } else // currently muted { // restore volume from oldVolume value this.setVolume(oldVolume); } // toggle muted flag isMuted = !isMuted; } // from interface IVolume public boolean isMuted() { // delegate to contained VolumeControl object return isMuted; } // returns a string representation of this class instance @Override public String toString() { // this method uses the "ternary" (three terms) operator // (expression ? true-value : false-value) // it's just a very compact if-else statement return "Radio: volume=" + (!this.isMuted() ? String.valueOf(volume) : "<muted>"); } }
Fuentes television y Personas
Prueba polimorfismo Television
Television[] tls={new Television("Miro"), new ColorTelevision("MediaMarkt",5)}; for(Television t:tls){ System.out.println(t); }
Clase ColorTelevision
package com.entertaiment; public class ColorTelevision extends Television { public ColorTelevision(String proveedor) { super(proveedor); } public ColorTelevision(String proveedor, int color) { super(proveedor); colorTv=color; } private int colorTv; public ColorTelevision(String marca, int volumen, String proveedor) { super(marca, volumen, proveedor); // TODO Auto-generated constructor stub } public String getMarca(){ return super.getMarca()+" TV!"; } public String toString(){ return super.toString()+" | "+colorTv; } }
String vs StringBuffer vs StringBuilder
Cambio validación marca
public void setMarca(String marca) { if (marca.equals("Sony") || marca.equals("Zenith") || marca.equals("Hitachi") || marca.equals("RCA")){ this.marca = marca; } }