Documentos de Académico
Documentos de Profesional
Documentos de Cultura
*
Ing. Christian Roberto Ibáñez Nangüelú
10 de Febrero de 2021
Resumen
Se abordaron los temas encapsulación y constructores durante la
sesión de 10-12 hrs. En el documento encontrarán el diagrama UML
y las clases correspondientes.
*
cribn@ib.upchiapas.edu.mx
Ing. Biomédica Programación Orientada a objetos
Índice
1. Clase principal 1
2. Clase Perro 2
Índice de figuras
1. Diagrama UML . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Lista de Algoritmos
1. Clase principal . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2. Clase Perro . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1. Clase principal
1 package ex1_9_feb_5b ;
2
3 /* *
4 *
5 * @author cribn
6 */
7 public class Ex1_9_FEB_5B {
8
9 /* *
10 * @param args the command line arguments
11 */
12 public static void main ( String [] args ) {
13 Perro p1 = new Perro ( " Solo - vino " ," Pug " ,12) ;
14 Perro p2 = new Perro () ;
15
16 System . out . println ( " --- Datos del can 1 ---" ) ;
17 System . out . println ( " Nombre : " + p1 . getNombre () ) ;
18 System . out . println ( " Raza : " + p1 . getRaza () ) ;
19 System . out . println ( " Altura : " + p1 . getAltura () ) ;
20 }
21
22 }
Algoritmos 1: Clase principal
2. Clase Perro
1 package ex1_9_feb_5b ;
2
3 /* *
4 *
5 * @author cribn
6 */
7 public class Perro {
8 /*
9 Atributos
10 */
11 private String Nombre ;
12 private String Raza ;
13 private float Altura ;
14
15 /*
16 Constructor
17 */
18 Perro () {
19 this . Altura = 13;
20 this . Raza = " Pug " ;
21 this . Nombre = " august " ;
22 System . out . println ( " --- Datos del can default ---" ) ;
23 System . out . println ( " Nombre : " + this . Nombre ) ;
24 System . out . println ( " Raza : " + this . Raza ) ;
25 System . out . println ( " Altura : " + this . Altura ) ;
26 }
27
28 Perro ( float Altura ) {
29 System . out . println ( " Constructor " ) ;
30 this . Altura = Altura ;
31 }
32
69 /*
70 Metodo set
71 */
72 public void setNombre ( String Nombre ) {
73 this . Nombre = Nombre ;
74 }
75
76 public void setRaza ( String Raza ) {
77 this . Raza = Raza ;
78 }
79
80 public void setAltura ( float Altura ) {
81 this . Altura = Altura ;
82 }
83
84 /*
85 Metodos propios de la clase
86 */
87 public void Comer () {
88 System . out . println ( " Comer " ) ;
89 }
90
91 public void Dormir () {
92 System . out . println ( " Dormir " ) ;
93 }
94
95 public void Ladrar () {
96 System . out . println ( " Ladrar " ) ;
97 }
98 }
Algoritmos 2: Clase Perro