incompatible types ?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: incompatible types ?

  1. #1
    Join Date
    Sep 2004
    Posts
    59

    incompatible types ?

    I get this error:

    incompatible types
    found : double
    required: java.lang.String
    zwembad = Lengte + Breedte + Diepte;


    Can anyone tell me what this means?

    i have checked my code several times.



    This is my code if you are interrested:

    // Its a swimming pool that uses length, width and depth.
    content is calculated with: length, width and depth


    import java.lang.String;

    public class Zwembad
    {
    double Lengte;
    double Breedte;
    double Diepte;
    double Inhoud;


    //Methode
    public Zwembad(double zbLengte, double zbBreedte, double zbDiepte)
    {
    Lengte = zbLengte;
    Breedte = zbBreedte;
    Diepte = zbDiepte;

    }
    //Methode

    public double setLengte ()
    {
    return Lengte;
    }

    public double setBreedte ()
    {
    return Breedte;
    }

    public double setDiepte ()
    {
    return Diepte;
    }

    public double getinhoud ()
    {
    return (Lengte + Breedte + Diepte);
    }

    public String toString()
    {
    String zwembad;
    zwembad = Lengte + Breedte + Diepte;
    return zwembad;
    }
    }


    this is the main file thats uses "zwembad"


    public class Main {

    public static void main (String [ ] argv)
    {
    Zwembad z = new Zwembad (2.0, 5.5, 1.5);
    System.out.println (z.getInhoud());
    }
    }
    My own java video tutorials, feel free to watch it.
    http://www.engineeringserver.com/for...amming-b311.0/ Need java help? For beginning and intermediate java coders!

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    String zwembad;
    zwembad = Lengte + Breedte + Diepte;
    return zwembad;

    You're adding 3 doubles together and assigning it to a String variable. If you add anything to a string however, it automatically gets casted into a string and concatenated.

    this should work.
    zwembad = "" + Lengte + Breedte + Diepte;

  3. #3
    Join Date
    Dec 2004
    Location
    france
    Posts
    35

    your code

    well check this out


    here we go :

    import java.lang.String;

    public class Zwembad
    {
    double Lengte;
    double Breedte;
    double Diepte;
    double Inhoud;


    //Methode
    public Zwembad(double zbLengte, double zbBreedte, double zbDiepte)
    {
    Lengte = zbLengte;
    Breedte = zbBreedte;
    Diepte = zbDiepte;

    }
    //Methode

    public double setLengte ()
    {
    return Lengte;
    }

    public double setBreedte ()
    {
    return Breedte;
    }

    public double setDiepte ()
    {
    return Diepte;
    }

    public double getinhoud ()
    {
    double p;
    p=Lengte + Breedte + Diepte;
    return p;
    }

    public String toString()
    {
    String zwembad;
    zwembad =" "+ Lengte + " "+Breedte + ""+Diepte+" ";
    return zwembad;
    }

    }


    //this is the main file thats uses "zwembad"

    class Main {

    public static void main (String [ ] argv)
    {
    Zwembad z = new Zwembad (2.0, 5.5, 1.5);
    System.out.println (z.getinhoud());
    }
    }

  4. #4
    Join Date
    Oct 2004
    Posts
    311
    Code:
    public String toString()
    {
    String zwembad;
    zwembad =" "+ Lengte + " "+Breedte + ""+Diepte+" ";
    return zwembad;
    }
    you only have to add the "" once, just like in Phaelax example.

  5. #5
    Join Date
    Dec 2004
    Location
    france
    Posts
    35
    well thats because this are the only thing to change in you're code
    in other word System.out.println ("Should be applayed to String type only")
    you got it?
    that 's why we're taking the String value of your variables
    it compil fine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center