java程序的一个简单错误
[code=Java][/code]import java.io.*;
public class Management
{
public static void main(String args[])
{
String age1=" ";
String hour1=" ";
String salary1=" ";
String xiaoshou1=" ";
String xiaoshouzong1=" ";
String ticheng1=" ";
try{
Employee emp1=new Employee();
System.out.println("Please input the name,age and salary of the manager:");
BufferedReader get=new BufferedReader(new InputStreamReader(System.in));
emp1.name=get.readLine();
age1=get.readLine();
emp1.age=Integer.parseInt(age1);
salary1=get.readLine();
emp1.salary=Double.parseDouble(salary1);
System.out.println(emp1.printinfo());
Employee emp2=new Technician();
System.out.println("Please input the name,age,hour and salary of the Technician:");
emp2.name=get.readLine();
age1=get.readLine();
emp2.age=Integer.parseInt(age1);
hour1=get.readLine();
emp2.hour=Double.parseDouble(hour1);
salary1=get.readLine();
emp2.salary=Double.parseDouble(salary1);
System.out.println(emp2.printinfo());
Employee emp3=new Salesman();
System.out.println("Please input the name,age,xiaoshou and salary of the Salesman:");
emp3.name=get.readLine();
age1=get.readLine();
emp3.age=Integer.parseInt(age1);
xiaoshou1=get.readLine();
emp3.xiaoshou=Double.parseDouble(xiaoshou1);
salary1=get.readLine();
emp3.salary=Double.parseDouble(salary1);
System.out.println(emp3.printinfo());
Employee emp4=new Salesmanager();
System.out.println("Please input the name,age,salary,xiaoshouzong and ticheng of the Salesmanager:");
emp4.name=get.readLine();
age1=get.readLine();
emp4.age=Integer.parseInt(age1);
salary1=get.readLine();
emp4.salary=Double.parseDouble(salary1);
xiaoshouzong1=get.readLine();
emp4.xiaoshouzong=Double.parseDouble(xiaoshouzong1);
ticheng1=get.readLine();
emp4.ticheng=Double.parseDouble(ticheng1);
System.out.println(emp4.printinfo());
}catch(IOException e){}
}
}
class Employee
{
String name;
int age;
double salary;
Employee() {}
Employee(String name,int age,double salary)
{
this.name=name;
this.age=age;
this.salary=salary;
}
String printinfo()
{
return "经理姓名: "+name+" 年龄:"+age+" 薪水:"+salary;
}
}
class Manager extends Employee
{
}
class Technician extends Employee
{
double hour;
Technician() {}
Technician(String name,int age,double hour)
{
this.name=name;
this.age=age;
this.hour=hour;
this.salary=hour*100;
}
String printinfo()
{
return "技术人员姓名:"+name+" 年龄:"+age+" 月工作时间:"+hour+" 薪水:"+salary;
}
}
class Salesman extends Employee
{
double xiaoshou;
Salesman() {}
Salesman(String name,int age,double xiaoshou)
{
this.name=name;
this.age=age;
this.xiaoshou=xiaoshou;
this.salary=xiaoshou*0.04;
}
String printinfo()
{
return "销售员姓名: "+name+" 年龄:"+age+" 销售额:"+xiaoshou+" 薪水:"+salary;
}
}
class Salesmanager extends Employee
{
double xiaoshouzong;
double ticheng;
Salesmanager() {}
Salesmanager(String name,int age,double salary,double xiaoshouzong)
{
this.name=name;
this.age=age;
this.salary=salary;
this.xiaoshouzong=xiaoshouzong;
this.ticheng=xiaoshouzong*0.005;
}
String printinfo()
{
return "销售经理姓名:"+name+" 年龄:"+age+" 薪水:"+salary+" 销售总额:"+xiaoshouzong+" 提成:"+ticheng;
}
}
求高手,错误指出,第30,42,56,58行中,找不到符号,我是java新手,啥都不懂,求大神帮我指出错误,谢谢啦!!
[解决办法]
都是同一个问题,就是你声明的是父类型引用,但是你用这个引用找子类的某个属性,这是不可以的要么你修改生成的引用,都是用具体的子类型, Technician emp2=new Technician();要不声明完后的父类型引用你强转一下,((Technician)emp2).hour=Double.parseDouble(hour1)。