File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ package Clases ;
2+
3+ public class Caja {
4+ private int alto ;
5+ private int profundo ;
6+ private int ancho ;
7+ //constructor
8+ public Caja (int alto , int profundo , int ancho ) {
9+ this .alto = alto ;
10+ this .profundo = profundo ;
11+ this .ancho = ancho ;
12+ }
13+ //calcular volumen de caja
14+ public int calcularVolumen () {
15+ return this .alto *this .ancho *this .profundo ;
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ package Clases ;
2+
3+ public class TestCaja {
4+ public static void main (String [] args ) {
5+ Caja caja1 =new Caja (2 , 3 , 6 );
6+ int c1 =caja1 .calcularVolumen ();
7+ Caja caja2 =new Caja (5 , 8 , 1 );
8+ int c2 =caja2 .calcularVolumen ();
9+ System .out .println ("El volumen de la caja 1 es : " +c1 );
10+ System .out .println ("El volumen de la caja 2 es : " +c2 );
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments