这是我的代码
public class RegMember {
private int regno;
private Cmember cmember;
private Vipmember vipmember;
private Clubs clubs;
private static int nextNo =1000;
public RegMember(Cmember cmember,Vipmember vipmember,Clubs clubs) {
this.vipmember=vipmember;
this.cmember=cmember;
this.clubs=clubs;
regno=++nextNo;
}
public static int getNextNo(){
return nextNo;
}
public String toString(){
return String.format("%-6d%-25s%-40s",regno,vipmember,cmember,clubs);
}
}
这是主类
import java.util.Scanner;
public class TestPerson {
/**
* Creates a new instance of <code>TestPerson</code>.
*/
public TestPerson() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
MemberType[] m = { new MemberType("Corporate Member"),new MemberType("VIP Member")
};
RegMember[] r = new RegMember[2];
Cmember cm;
Vipmember vip;
Scanner s = new Scanner(System.in);
for(int i=0;i<r.length;i++){
System.out.println("your reg no is :"+(RegMember.getNextNo()+1));
for(int a=0;a<m.length;a++){
System.out.println((a+1)+". "+m[a].toString());
}
System.out.println("Enter Your selection:");
int sel=s.nextInt();
if(sel==1){
s.nextLine();
System.out.println(" enter name:");
String Name=s.nextLine();
System.out.println(" enter Handphone:");
String Hpnum=s.next();
System.out.println(" enter Age:");
int age=s.nextInt();
System.out.println("enter Company Name:");
String CompanyName=s.nextLine();
cm = new Cmember(Name,Hpnum,age,CompanyName);
}
else{
s.nextLine();
System.out.println(" enter name:");
String Name=s.nextLine();
System.out.println(" enter Handphone:");
String Hpnum=s.next();
System.out.println(" enter Age:");
int age=s.nextInt();
System.out.println("enter Email:");
String email=s.next();
vip = new Vipmember(Name,Hpnum,age,email);
}
if(sel==1){
r[i]=new RegMember(cm);
}
else{
r[i]=new RegMember(vip);
}
s.nextLine();
}
displayInfor(r);
}
public static void displayInfor( RegMember[]r){
for(int i =0; i<r.length;i++)
System.out.println( r[i].toString());
}
}
这是我面临的问题。
error: constructor
RegMember类中的RegMember不能应用于给定类型; r[i]=new RegMember(cm);
^
需要:Cmember,Vipmember,Clubs
找到:Cmember
原因:实际和正式论点 list 的长度不同
error: constructor
RegMember类中的RegMember不能应用于给定类型; r[i]=new RegMember(vip);
^
需要:Cmember,Vipmember,Clubs
找到:贵宾成员(member)
原因:实际和正式论点 list 的长度不同
2个错误
最佳答案
RegMember
没有使用单个Cmember
作为参数的构造函数。这就是为什么新的RegMember(cm)
无法编译的原因。
同样,它也没有采用单个Vipmember
的构造函数。因此,新的RegMember(vip)
也无法编译。