我是Java的新手,我在构造函数方面遇到了一些问题。
这里是错误:“未定义构造函数Transaction(Type_Transaction,String,Particulier,Agent_immobilier)”
我想要做的是创建一个具有今天日期属性的对象(格式字符串)。因此,在我的构造函数中,我不想放置参数“ date”。我也在将今天的日期转换为字符串。
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);
}
答案 0 :(得分:0)
根据您的错误,您需要向构造函数添加一个字符串参数,如下所示:
private Transaction(Type_Transaction type_transaction, String theString, Particulier leparticulier, Agent_immobilier lagent) {
您的代码实际上并未引发错误。