0

I'm new to Java and I have some problems with the constructor.

Here is the error : "The constructor Transaction(Type_Transaction, String, Particulier, Agent_immobilier) is undefined"

What I want to do is to create objects with an attribute of today's date (format string). So in my constructor I don't want to put an argument "date". I'm also converting the today's date in string.

public class Transaction {

private String date_transaction;
private Particulier leparticulier;
private Agent_immobilier lagent;
private Type_Transaction type_transaction;
private DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");



private Transaction(Type_Transaction type_transaction, Particulier leparticulier, Agent_immobilier lagent) {
    super();
    this.type_transaction=type_transaction;
    this.leparticulier=leparticulier;
    this.lagent=lagent;
    this.date_transaction = Date_Ajd();
}

public String Date_Ajd(){
    Date date=new Date();   
    String date_ajd = dateFormat.format(date);
    return date_ajd;

}

public static void main(String[] args) {
    Particulier Alfred=new Particulier(xxxx);
    Agent_immobilier Lilian=new Agent_immobilier(xxxxx);
    Transaction number1 = new    Transaction(Type_Transaction.Location,Alfred,Lilian);
}
Lana James
  • 77
  • 9
  • Are you sure that the code you posted actually generates this error? It seems to me that it should not. – Tim Biegeleisen Apr 27 '19 at 15:14
  • Well, errors don't lie. If you didn't define constructor which accepts `Type_Transaction, String, Particulier, Agent_immobilier` your class wouldn't know what to do with these arguments. Define such constructor and provide it with code which will do what you want. – Pshemo Apr 27 '19 at 15:15
  • `Type_Transaction.Location` is not `Type_Transaction`! – Youcef LAIDANI Apr 27 '19 at 15:16
  • The biggest problem I see here is that your constructor is calling an overridable method: See https://stackoverflow.com/questions/10337011/how-to-fix-constructor-calls-overridable-method – PowerStat Apr 27 '19 at 15:19
  • The fact is that I don't understand why there is a (String) in my error while I don't want to define String date_transaction when I'm creating an object – Lana James Apr 27 '19 at 15:22

1 Answers1

0

According to your error, you need to add a string parameter to the constructor as below:

private Transaction(Type_Transaction type_transaction, String theString, Particulier leparticulier, Agent_immobilier lagent) {

Your code does not actually throw an error.

TheChubbyPanda
  • 1,721
  • 2
  • 16
  • 37