On Mar 31, 5:55 am, el mio uno y dos <[email protected]> wrote:
> Hello bulimic,this is that i do, please i am a new on java, but i believe 
> that now is more clear the code. What do you think?
>
> public class Cilindro {
> double pi = Math.PI;
> double area;
> double perimetro;
>
>    public Cilindro()
>    {
>
>     }
>
>     public double area(double r, double h){
>
>        area = (2*pi*r*h) + (2*pi*r*r);
>
>        return this.area;
>     }
>
>     public double perimetro(double r, double h){
>          perimetro = (4*pi*r)+(2*h);
>
>         return this.perimetro;
>
>     }
>
> }
>
> public class Circulo extends Cilindro{
Since circulo does not have any incentive to inherit from cilindro,
circulo's class declaration can be written this way:
public class Circulo{
}

Like you, I am learning too. Good luck.
>
>       public Circulo(){
>
>         }
>
>         public double area(double r){
>
>             area = pi*r*r;
>             return this.area;
>         }
>
>         public double perimetro(double r){
>             perimetro = 2*pi*r;
>
>             return this.perimetro;
>         }
>
>     }
>
> public class Main {
>
>     /**
>      * @param args the command line arguments
>      */
>     public static void main(String[] args) {
>         // TODO code application logic here
>         Circulo obj1 = new Circulo();
>         Cilindro obj2=new Cilindro();
>             double radio  ,altura ;
>             Scanner input = new Scanner(System.in);
>
>             System.out.println("Ingresa Radio: ");
>             radio = input.nextFloat();
>             System.out.println("Ingresa Altura: ");
>             altura = input.nextFloat();
>
>             System.out.println("Area del circulo: " + obj1.area(radio));
>             System.out.println("Perimetro del circulo: " + 
> obj1.perimetro(radio));
>             System.out.println("Area del cilindro: " + 
> obj2.area(radio,altura));
>             System.out.println("Perimetro del cilindro: " + 
> obj2.perimetro(radio,altura));
>     }
>
>
>
> }
> > Date: Mon, 30 Mar 2009 14:32:33 -0700
> > Subject: [java programming] Re: Logic error!
> > From: [email protected]
> > To: [email protected]
>
> > On Mar 31, 3:27 am, el mio uno y dos <[email protected]> wrote:
> > > Hello bulimic, i think that circulo is not a inner class of cilindro. I 
> > > think that circulo is a subclass of cilindro. I send a copy of how i do 
> > > it. Please see it and tell me if is correct.
> > Hello. I did not receive any copy. Anyway, we can discuss here.
>
> > Circulo inherits cilindro is odd. I think it would be more efficient
> > if cilindro extends circulo as it can take advantage of code re-use.
> > For example:
> > public class Circulo{
> > public double area(double radius){
> > }
> > public double perimetro(double radius){
> > }
> > }
>
> > public class Cilindro extends Circulo{
> > public double area(double radius, double height){
> > // Use circulo's methods to calculate cilindro's area. Then
> > return.
> > double areaCirculo=area(radius), perimetroCirculo=perimetro
> > (radius);
> > }
> > }
>
> > > > Date: Mon, 30 Mar 2009 11:53:33 -0700
> > > > Subject: [java programming] Re: Logic error!
> > > > From: [email protected]
> > > > To: [email protected]
>
> > > > On Mar 31, 1:36 am, jose luis garcia <[email protected]> wrote:
> > > > > *Hello everybody... I have a problem. I wrote a code for a program 
> > > > > that have
> > > > > 1 superclass and 1 class extends. the code it`s follow:*
>
> > > > > //Programa que realiza algunos calculos mediante las caracteristicas 
> > > > > de un
> > > > > cilindro
>
> > > > > package cilindro;
>
> > > > > // @author louis
>
> > > > > import java.util.Scanner;
>
> > > > > public class Cilindro {
> > > > >      double pi = Math.PI;
>
> > > > >    public Cilindro(){
> > > > >       // super();
>
> > > > >     }
>
> > > > >     public double areaCilindro(double r, double h){
> > > > >         double area = (2*pi*r*h) + (2*pi*r*r);
>
> > > > >         return area;
> > > > >     }
>
> > > > >     public double perimetroCilindro(double r, double h){
> > > > >         double perimetro = (4*pi*r)+(2*h);
>
> > > > >         return perimetro;
>
> > > > >     }
>
> > > > >     public class Circulo extends Cilindro{
>
> > > > >         Circulo(){
> > > > >             super();
> > > > >         }
>
> > > > >         public double areaCirculo(double r){
>
> > > > >             double area = pi*r*r;
> > > > >             return area;
> > > > >         }
>
> > > > >         public double perimetroCirculo(double r){
> > > > >             double perimetro = 2*pi*r;
>
> > > > >             return r;
> > > > >         }
>
> > > > >     }
>
> > > > >         public static void main(String[] args) {
>
> > > > >            // Cilindro obj = null;
> > > > >             Circulo obj1 = null;
> > > > I suspect the culprit is the inner class. If I remember correctly, an
> > > > inner class type declaration should be like:
> > > > Cilindro.Circulo obj1 = null;
>
> > > > >             double radio = 0,altura = 0;
> > > > >             Scanner input = new Scanner(System.in);
>
> > > > >             System.out.println("Ingresa Radio: ");
> > > > >             radio = input.nextFloat();
>
> > > > >            /* System.out.println("Ingresa altura: ");
> > > > >             altura = input.nextFloat();
> > > > >             */
> > > > >             String resultado = "Area del circulo: " +
> > > > > obj1.areaCirculo(radio);
>
> > > > >             System.out.println(resultado);
>
> > > > >     }
>
> > > > > }
>
> > > > > *Netbeans not generate any error. But at the moment that run the 
> > > > > program and
> > > > > insert a float, Netbeans generate me this message:*
>
> > > > > run:
> > > > > Ingresa Radio:
> > > > > Exception in thread "main" java.lang.NullPointerException
> > > > >         at cilindro.Cilindro.main(Cilindro.java:66)
> > > > > 2.23
> > > > > Java Result: 1
> > > > > GENERACIÓN CORRECTA (tiempo total: 3 segundos)
>
> > > > > *
> > > > > I`m sure that is a logic error... help me please. Thanks!
> > > > > *
>
> > > _________________________________________________________________
> > > Descubre todas las formas en que puedes estar en contacto con amigos y 
> > > familiares.http://www.microsoft.com/windows/windowslive/default.aspx
>
> _________________________________________________________________
> ¿Quieres ver los mejores videos de MSN? Enciende Messenger 
> TVhttp://messengertv.msn.com/mkt/es-es/default.htm

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to