请教下高手,这个报错The constructor worker(int, String, float) is undefined是怎么回事啊
packagearraylist;importjava.util.*;publicclassarraylist2{publicstaticvoidmain(String[...
package arraylist;
import java.util.*;
public class arraylist2
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("输入号码");
int num=sc.nextInt();
System.out.println("输入姓名");
String name=sc.next();
System.out.println("输入薪水");
float sal=sc.nextFloat();
Emp emp=new Emp();
emp.addw(new worker(num,name,sal));
System.out.println(new worker().name);
}
}
class worker
{
int num;
String name;
float sal;
public void worker(int num,String name,float sal)
{
this.name=name;
this.num=num;
this.sal=sal;
}
}
class Emp
{
ArrayList a1=new ArrayList();
public void addw(worker w1)
{
a1.add(w1);
}
} 展开
import java.util.*;
public class arraylist2
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("输入号码");
int num=sc.nextInt();
System.out.println("输入姓名");
String name=sc.next();
System.out.println("输入薪水");
float sal=sc.nextFloat();
Emp emp=new Emp();
emp.addw(new worker(num,name,sal));
System.out.println(new worker().name);
}
}
class worker
{
int num;
String name;
float sal;
public void worker(int num,String name,float sal)
{
this.name=name;
this.num=num;
this.sal=sal;
}
}
class Emp
{
ArrayList a1=new ArrayList();
public void addw(worker w1)
{
a1.add(w1);
}
} 展开
2个回答
展开全部
import java.util.*;
public class Arraylist2 //注意java编程规范,谈旅扰类名一般是首字母大写,
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("输入号码");
int num=sc.nextInt();
System.out.println("输入姓名");
String name=sc.next();
System.out.println("输入薪水");
float sal=sc.nextFloat();
Emp emp=new Emp();
Worker w=new Worker(num,name,sal);
emp.addw(w); //镇瞎这里进行了修改
System.out.println(w.name);/含旦/应为这里需要用到w.name
}
}
class Worker
{
int num;
String name;
float sal;
public Worker(int num,String name,float sal) //这里你写成了方法把void 去掉
{
this.name=name;
this.num=num;
this.sal=sal;
}
}
class Emp
{
ArrayList a1=new ArrayList();
public void addw(Worker w1)
{
a1.add(w1);
}
}
public class Arraylist2 //注意java编程规范,谈旅扰类名一般是首字母大写,
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("输入号码");
int num=sc.nextInt();
System.out.println("输入姓名");
String name=sc.next();
System.out.println("输入薪水");
float sal=sc.nextFloat();
Emp emp=new Emp();
Worker w=new Worker(num,name,sal);
emp.addw(w); //镇瞎这里进行了修改
System.out.println(w.name);/含旦/应为这里需要用到w.name
}
}
class Worker
{
int num;
String name;
float sal;
public Worker(int num,String name,float sal) //这里你写成了方法把void 去掉
{
this.name=name;
this.num=num;
this.sal=sal;
}
}
class Emp
{
ArrayList a1=new ArrayList();
public void addw(Worker w1)
{
a1.add(w1);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询