java小程序出错 15
/**1、实现一个名为Person的类和它的子类Employee,Manager是Employee的子类,设计一个接口Add用于涨工资,普通员工一次能涨10%,经理能涨2...
/**
1、实现一个名为Person的类和它的子类Employee, Manager是Employee的子类,设计一个接口Add用于涨工资
,普通员工一次能涨10%,经理能涨20%。
具体要求如下:
(1)Person类中的属性有:姓名name(String类型),地址address(String类型)并写出该类的构造方法;
(2)Employee类中的属性有:工号ID(String型),工资wage(double类型),工龄(int型),写出该类的
构造方法;
(3)Manager类中的属性有:级别level(String类型),写出该类的构造方法;
编写一个测试类,产生一个员工和一个经理并输出其具有的信息。
*/
public class Test{
String name;
String address;
public static void main(String[] args)
{
Employee e=new Employee("119-1",2211.1,3);
e.show();
Manager m=new Manager("1等");
m.show();
Add a=new AddWage();
a.employee();
a.manager();
}
public interface Add{
int employee(double wage);
int manager(double wage);
}
public class AddWage implements Add{
public int employee(){
return wage+=wage*0.1;
}
public int manager(double wage){
return wage+=wage*0.1;
}
}
class Person
{
Person p=new Person("人类","地球");
p.show();
public Person(String name,String address){
this.name=name;
this.address=address;
public void show(){
System.out.printf("我的名字是:%s,住址是:%s",name,address);
}
}
}
class Employee extends Person
{
String ID;
double wage;
int gling;
public Employee(String ID,double wage,int gling)
{
this.ID=ID;
this.wage=wage;
this.gling=gling;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s,ID号是%s,工资是:%d,工龄是:%d",this.name,this.address,ID,wage,gling);
}
}
class Manager extends Employee
{
String level;
public Manager(String level){
this.level=level;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s,ID号是%s,工资是:%d,工龄是:%d,等级是:%s",this.name,this.address,this.ID,this.wage,this.gling,level);
}
}
} 展开
1、实现一个名为Person的类和它的子类Employee, Manager是Employee的子类,设计一个接口Add用于涨工资
,普通员工一次能涨10%,经理能涨20%。
具体要求如下:
(1)Person类中的属性有:姓名name(String类型),地址address(String类型)并写出该类的构造方法;
(2)Employee类中的属性有:工号ID(String型),工资wage(double类型),工龄(int型),写出该类的
构造方法;
(3)Manager类中的属性有:级别level(String类型),写出该类的构造方法;
编写一个测试类,产生一个员工和一个经理并输出其具有的信息。
*/
public class Test{
String name;
String address;
public static void main(String[] args)
{
Employee e=new Employee("119-1",2211.1,3);
e.show();
Manager m=new Manager("1等");
m.show();
Add a=new AddWage();
a.employee();
a.manager();
}
public interface Add{
int employee(double wage);
int manager(double wage);
}
public class AddWage implements Add{
public int employee(){
return wage+=wage*0.1;
}
public int manager(double wage){
return wage+=wage*0.1;
}
}
class Person
{
Person p=new Person("人类","地球");
p.show();
public Person(String name,String address){
this.name=name;
this.address=address;
public void show(){
System.out.printf("我的名字是:%s,住址是:%s",name,address);
}
}
}
class Employee extends Person
{
String ID;
double wage;
int gling;
public Employee(String ID,double wage,int gling)
{
this.ID=ID;
this.wage=wage;
this.gling=gling;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s,ID号是%s,工资是:%d,工龄是:%d",this.name,this.address,ID,wage,gling);
}
}
class Manager extends Employee
{
String level;
public Manager(String level){
this.level=level;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s,ID号是%s,工资是:%d,工龄是:%d,等级是:%s",this.name,this.address,this.ID,this.wage,this.gling,level);
}
}
} 展开
3个回答
展开全部
我改动了一下:
public class Test{
public static void main(String[] args)
{
Employee e=new Employee("119-1", "张三其", "湖南长沙", 3000, 3);
e.show();
e.addWage();
System.out.println("涨工资后:");
e.show();
Manager m=new Manager("119-2", "李师煊", "湖南长沙", 5000, 8, "1等");
m.show();
m.addWage();
System.out.println("涨工资后:");
m.show();
}
}
interface Add{
void addWage();
}
class Person {
protected String name;
protected String address;
public Person(String name,String address){
this.name=name;
this.address=address;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s\n",name,address);
}
}
class Employee extends Person implements Add {
String ID;
double wage;
int gling;
public Employee(String ID, String name, String address, double wage, int gling) {
super(name, address);
this.ID = ID;
this.wage = wage;
this.gling = gling;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s,ID号是%s,工资是:%f,工龄是:%d\n", this.name, this.address, ID, wage, gling);
}
@Override
public void addWage() {
wage *= 1.1;
}
}
class Manager extends Employee implements Add{
String level;
public Manager(String ID, String name, String address, double wage, int gling, String level){
super(ID, name, address, wage, gling);
this.level=level;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s,ID号是%s,工资是:%f,工龄是:%d,等级是:%s\n", this.name, this.address, this.ID, this.wage, this.gling, level);
}
public void addWage(){
wage *= 1.2;
}
}
运行测试:
我的名字是:张三其,住址是:湖南长沙,ID号是119-1,工资是:3000.000000,工龄是:3
涨工资后:
我的名字是:张三其,住址是:湖南长沙,ID号是119-1,工资是:3300.000000,工龄是:3
我的名字是:李师煊,住址是:湖南长沙,ID号是119-2,工资是:5000.000000,工龄是:8,等级是:1等
涨工资后:
我的名字是:李师煊,住址是:湖南长沙,ID号是119-2,工资是:6000.000000,工龄是:8,等级是:1等
public class Test{
public static void main(String[] args)
{
Employee e=new Employee("119-1", "张三其", "湖南长沙", 3000, 3);
e.show();
e.addWage();
System.out.println("涨工资后:");
e.show();
Manager m=new Manager("119-2", "李师煊", "湖南长沙", 5000, 8, "1等");
m.show();
m.addWage();
System.out.println("涨工资后:");
m.show();
}
}
interface Add{
void addWage();
}
class Person {
protected String name;
protected String address;
public Person(String name,String address){
this.name=name;
this.address=address;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s\n",name,address);
}
}
class Employee extends Person implements Add {
String ID;
double wage;
int gling;
public Employee(String ID, String name, String address, double wage, int gling) {
super(name, address);
this.ID = ID;
this.wage = wage;
this.gling = gling;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s,ID号是%s,工资是:%f,工龄是:%d\n", this.name, this.address, ID, wage, gling);
}
@Override
public void addWage() {
wage *= 1.1;
}
}
class Manager extends Employee implements Add{
String level;
public Manager(String ID, String name, String address, double wage, int gling, String level){
super(ID, name, address, wage, gling);
this.level=level;
}
public void show(){
System.out.printf("我的名字是:%s,住址是:%s,ID号是%s,工资是:%f,工龄是:%d,等级是:%s\n", this.name, this.address, this.ID, this.wage, this.gling, level);
}
public void addWage(){
wage *= 1.2;
}
}
运行测试:
我的名字是:张三其,住址是:湖南长沙,ID号是119-1,工资是:3000.000000,工龄是:3
涨工资后:
我的名字是:张三其,住址是:湖南长沙,ID号是119-1,工资是:3300.000000,工龄是:3
我的名字是:李师煊,住址是:湖南长沙,ID号是119-2,工资是:5000.000000,工龄是:8,等级是:1等
涨工资后:
我的名字是:李师煊,住址是:湖南长沙,ID号是119-2,工资是:6000.000000,工龄是:8,等级是:1等
追问
super(name, address);解释下super用来干什么?是用来调用父类的属性吗?
追答
super(name,address)表示调用父类的构造方法。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询