Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: constructor in class cannot be applied to given types

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default constructor in class cannot be applied to given types

    I got stuck at this point i have no idea how to solve it. I want the class Test to make a new Auto object.

    The error im getting:
    constructor Auto in class Auto cannot be applied to given types;
    required: no arguments
    found: int,int, double
    reason actual and formal argument lists differ in length

    This is the Test class:
    public class Test
    {
    Auto otto;

    public Test()
    {
    otto = new Auto(10000, 70, 7.5);
    otto.fahren(20);
    otto.anzeigen();
    otto.fahren(60);
    otto.anzeigen();
    otto.fahren(20);
    otto.anzeigen();
    otto.fahren(30);
    otto.anzeigen();
    otto.fahren(80);
    otto.anzeigen();
    otto.fahren(280);
    otto.anzeigen();
    }
    }

    This is the Auto class:

    public class Auto
    {
    double kmStand;
    double Tank;
    double verbrauch1;
    double verbrauch;

    public Auto(double KmStand, double Tank, double Verbrauch)
    {
    kmStand = KmStand;
    Tank = Tank;
    verbrauch = Verbrauch;



    }

    // public void setkmStand(double newKmStand)
    // {
    // kmStand = newKmStand;
    // }

    // public void setTank(double newTank)
    // {
    // Tank = newTank;
    // }

    // public void setVerbrauch(double newVerbrauch)
    // {
    // verbrauch = newVerbrauch;
    // }

    public void fahren(double km)
    {
    kmStand += km;
    verbrauch1 = km * (verbrauch/100);
    Tank -= verbrauch1;
    }

    public void anzeigen()
    {
    System.out.println("Ihr Kilometerstand beträgt " + kmStand + " km.");
    System.out.println("Ihr Benzinstand beträgt " + Tank + " Liter.");
    System.out.println("Ihr Verbrauch beträgt " + verbrauch + "Liter/100 km.");
    }
    }

    would appreciate any help

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: constructor in class cannot be applied to given types

    I'm not certain the problem. It appears that the creation of the Auto class is expecting a constructor with no arguments. Is it possible that your public Auto class (which is in a different file) is conflicting with another Auto class that requires no constructor values? Try temporarily renaming your public Auto class to Auto1. And remember that the file name for the public Auto1 class must be Auto1.java.

    Regards,
    Jim

Similar Threads

  1. errror constructor class cannot be applied to give types
    By Aosora in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 13th, 2014, 07:24 AM
  2. [SOLVED] method in class cannot be applied
    By ange in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 30th, 2013, 05:03 AM
  3. How to avoid a constructor of class A be extended to Class B?
    By chaitra1987 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: May 28th, 2013, 11:46 PM
  4. **Constructor in class cannot be applied to given types;...
    By bassie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 2nd, 2012, 02:15 PM
  5. which class has a default constructor? (Req. guidance on constructor)
    By DragBall in forum Java Theory & Questions
    Replies: 1
    Last Post: June 27th, 2012, 04:42 PM

Tags for this Thread