Buenas tardes, dejo mi solución al ejercicio CU00912C del curso pdf de programación avanzada Java.
Saludos
package claseCU00912C;
public class Cadena12Caracteres implements Cloneable {
private String cad1, cad2,cad3,cad4;
public void setCad1(String cad1) {
this.cad1 = cad1;
}
public void setCad2(String cad2) {
this.cad2 = cad2;
}
public void setCad3(String cad3) {
this.cad3 = cad3;
}
public void setCad4(String cad4) {
this.cad4 = cad4;
}
public Cadena12Caracteres(String pCad1,String pCad2,String pCad3,String pCad4) {
this.cad1 = pCad1;
this.cad1 = pCad1;
this.cad2 = pCad2;
this.cad3 = pCad3;
this.cad4 = pCad4;
}
public Cadena12Caracteres clone() {
Cadena12Caracteres clonado = new Cadena12Caracteres(cad1, cad2, cad3, cad4);
return clonado;
}
public String toString() {
return this.cad1+this.cad2+this.cad3+this.cad4;
}
}
package claseCU00912C;
public class EjercicioCU00912C {
public static void main(String[] args) {
char[] pchar = new char[12];
String cadenaCeros = new String(pchar).replace("\0", "0");
String cadenaUnos = new String(pchar).replace("\0", "1");
Cadena12Caracteres c1;
c1 = new Cadena12Caracteres(cadenaCeros, cadenaCeros, cadenaCeros, cadenaCeros);
Cadena12Caracteres c2 = c1.clone();
Cadena12Caracteres c3 = c1.clone();
Cadena12Caracteres c4 = c1.clone();
Cadena12Caracteres c5 = c1.clone();
c2.setCad1(cadenaUnos);
c3.setCad2(cadenaUnos);
c4.setCad3(cadenaUnos);
c5.setCad4(cadenaUnos);
System.out.println(c1.toString());
System.out.println(c2.toString());
System.out.println(c3.toString());
System.out.println(c4.toString());
System.out.println(c5.toString());
}
}