Undefined Constructor Java

java constructor
implicit super constructor is undefined
the constructor is undefined processing
subclass constructor java
the constructor is undefined lombok
java undefined error
the constructor file(string) is undefined
allargsconstructor the constructor is undefined

I wrote a small program which has three classes: Carpet, Calculator and Floor.

The carpet class will be called to be multiplied with the floor class by using the calculator class in the main. However, I found that when using double as a return type in the calculator class I came across constructor undefined error.

I found out to be the issue of the calculator class I have a method getTotalCost() to return the cost of floor and carpet. why can't I just pass two objects as a parameter in calculator when called in main. I used primitive return type of double in calculator class.

Please help me rewrite the calculator class and explain to me why I can't use the primitive types class but instead, I must use the class name in the calculator field declaration of floor and carpet. Why must the class name for floor and carpet to be passed into the constructor in order to build the object? What is the fix in getTotalCost() as if you use the class name to declare two instance fields then surely the error will be something like this:

- The operator * is undefined for the argument 
    type(s) Floor, Carpet
- Occurrence of 'carpet'
- 1 changed line

Trying to use the classes created but received an error.

Carpet carpet = new Carpet(3.5);
Floor floor = new Floor(2.75, 4.0);

passing floor and carpet in the parameter of calculator. //constructor not defined Calculator calculator = new Calculator(floor,carpet);

public class Calculator {

    private double floor;
    private double carpet;

    public Calculator()
    {
    }

    public Calculator(double floor, double carpet) {
        this.carpet=carpet;
        this.floor=floor;
    }

    public double getTotalCost() 
    {
        return (this.floor*this.carpet);
    }
}


public class Floor {

private double width;
private double length;

    public Floor()
    {
    }

    public Floor(double width,double length)
    {
        this.length=length;
        this.width=width;
    }

    public void setWidth(double width) 
    {
        if (this.width < 0) {
            this.width=0;
        }
        else {
            this.width=width;
        }
    }

    public void setLength(double length) 
    {
        if (this.length < 0) {
            this.length=0;
        }
        else {
            this.length=length;
        }
    }

    public double getArea() 
    {
        return (this.length * this.width);
    }
}


public class Carpet {

    private double cost;

    public Carpet()
    {
    }

    public Carpet(double cost)
    {
        this.cost=cost;
    }

    public void setCost(double cost) 
    {
        if (cost < 0) {
            this.cost=0;
        }
        else {
            this.cost=cost;
        }
    }

    public double getCost() 
    {
        return this.cost;
    }
}

Since your Calculator class has only the default constructor (one without any args) and a constructor that only accepts double, double, you can't create a Calculator instance providing a Carpet instance and a Floor instance.

So you have 2 options:

  1. Pass the floor area and carpet cost to the current constructor.

    Calculator calculator = new Calculator(floor.getArea(), carpet.getCost());

  2. Change the constructor to accept a Carpet instance and a Floor instance (then your Calculator class logic also should be modified)

public class Calculator {

    private Floor floor;
    private Carpet carpet;

    public Calculator() {
    }

    public Calculator(Floor floor, Carpet carpet) {
        this.carpet=carpet;
        this.floor=floor;
    }

    public double getTotalCost() 
    {
        return (this.floor.getArea() * this.carpet.getCost());
    }
}


Java Error: The constructor is undefined, Add this to your class: public WeightIn(){ }. Please understand that default no-​argument constructor is provided only if no other constructor is written; If you write​  Java - the constructor is undefined. I have an abstract class GeometricObject, which is extended by a base class Rectangle. In the superclass, I have two constructors provided: In the rectangle class, I've created another constructor, which is supposed to invoke the GeometricObject arguments constructor. Correct me if I'm wrong, but that's the proper way to give values for "color" and "filled" for a Rectangle object.


The parameters of the Calculator class is (double, double) so it will not accept Floor and Carpet objects. You can either call the constructor like:

Calculator calc = new Calculator(carpet.getCost(), floor.getCost());

Or change the constructor to the following:

Calculator (Floor f, Carpet c) {
    this.floor = f.getCost();
    this.carpet = c.getCost();
}

Constructor Is Undefined, Eclipse allows me to fix the undefined constructor (line 4 of TestToString.java) by removing the arguments but that is not what I am trying to do. My current work needs to do the development based on open soure software. There is a class defined as DirLocator.java The code is as follows. public final class DirLocator implements IResourceLocator { /** The folder relative to which resources are resolved. */ private File dir; /** * Initializes the locator using the given directory.


You cannot multiply objects. Looks, like you wand to multiply carpet on a floor and get... Something? This is not working like this, think about it a little deeper - the fact is you really want to multiply the carpet square (number of square meters to be more specific) on cost of 1 square meter (number of currency). When you understand this, you should have no trouble to correct your code, so the Calculator would haveFloorandCarpet` fields and be able to calculate total cost based on floor square and carpet cost @Udith Gunaratna answered

Constructors in Java - A complete study!!, when the method is not defined in that class. If you getting these errors for methods related to String or Collection Classes most likely the problem is because of JDK compliance level or installed JRE. All these methods compiles with JDK 1.5 or above. The simplest way around this is for the base class to not declare a constructor (and thus have the default, no-arg constructor) or have a declared no-arg constructor (either by itself or alongside any other constructors).


ERROR - The method is undefined for the type, is an instance method that usually has the same name as the class, and can be used to set the values of the members of an object, either to default or to user-defined values. Just in point of fact, I am only using ComputerPlayer as a platform to extend Player to the types of computer player bots I am writing, which is why there is nothing but a constructor there, which, again, is what I thought I needed to use inheritance for the respective child classes.


Why is super class constructor always called, A friendly place for programming greenhorns! Jump to bottom of page. Forums Register Login. Java » Beginning Java. Constructor Undefined  “Implicit super constructor is undefined for default constructor. Must define an explicit constructor” This compilation error is caused because the super constructor is undefined. In Java, if a


What is a Constructor?, Java doesn't require a constructor when we create a class. However Implicit super constructor Vehicle() is undefined for default constructor. "Implicit super constructor is undefined for default constructor. Must define an explicit constructor" This compilation error occurs because the default super constructor is undefined. In Java, if a class does not define a constructor, compiler will insert a default no-argument constructor for the class by default.