public class Text { }
public static void main(String[] args) { Position a=new Position(); a.x(3, 5); a.y(4, 6); a.compareTo(); }
8 package gongzi;
public class Person { String name;
String address;
Person(String n,String a){ name=n; address=a; }
}
public class Employee extends Person{
String ID; double wage; int age;
Employee(String n,String a,String I,double w,int ag){
super(n,a); ID=I;
wage=w; age=ag; } }
public class Manager extends Employee implements A{ String level;
Manager(String n,String a,String I,double w,int ag,String l){ super(n,a,I,w,ag);
level=l;
}
public void zhangwage(){
Employee a=new Employee(\,\,\,3000,5); if(this.level==\经理\){
a.wage=a.wage+a.wage*0.2; }
else{
a.wage=a.wage+a.wage*0.1; }
System.out.println(\姓名:\+super.name+\地址:\+super.address+\工号:\+super.ID+\工资:\+super.wage+\年龄:\+super.age+\职位:\+this.level); }
}
interface A{ }
public class Test {
public static void main(String[] args) {
Manager a=new Manager(\,\,\,3000,25,\经理\);
a.zhangwage();
public abstract void zhangwage();
} }
9 package goujianpingguo;
public class apple { public apple() {
System.out.println(\创建了一个苹果类的对象\); }
}
public class banana { public banana()
{
System.out.println(\创建了一个香蕉类的对象\);
} }
public class grape { public grape()
{
System.out.println(\创建了一个葡萄类的对象\); }
}
interface Fruit{
public abstract void choose(String a); }
public class gardener implements Fruit {
}
public void choose(String a){
if(a.equals(\苹果\)){ apple b=new apple(); }
else if(a.equals(\香蕉\)){ banana b=new banana(); }
else if(a.equals(\葡萄\)){ grape b=new grape(); } else{
System.out.println(\没有这种水果!\);
} }
import java.util.Scanner;
public class Test {
public static void main(String[] args) { Scanner sca=new Scanner(System.in);
String s=sca.next();
gardener p=new gardener(); p.choose(s); }
}
10 package Cala;
public abstract class ColaEmployee {
String name; int year; int month; int day;
ColaEmployee(){}
ColaEmployee (String name,int year,int month,int day){ this.name=name;
this.year=year; this.month=month;
this.day=day; }
abstract double getSalary(int month);
}
public class SalariedEmp extends ColaEmployee{ double salary; SalariedEmp(){}
SalariedEmp(String name,int year,int month,int day,double salary){ super(name,year,month,day);
this.salary=salary;
}
double getSalary(int month){ if(month==this.month){ salary+=100;
}
return salary;
}
}
public class HourlyEmplo extends ColaEmployee{ double hourSalary; int hour;
HourlyEmplo(){}
HourlyEmplo(String name,int
year,int
month,int
hourSalary,int hour){ super(name,year,month,day); this.hourSalary=hourSalary; this.hour=hour; }
double getSalary(int month){ double salary=0; if(hour<=160){
salary=hour*hourSalary; }
else{
salary=160*hourSalary+(hour-160)*hourSalary*1.5; }
if(month==this.month){ salary+=100; }
return salary;
} }
public class SalesEmployee extends ColaEmployee{ double monthSalary; double rate;
SalesEmployee(){}
SalesEmployee(String
name,int year,int month,int day,doubleday,double
monthSalary,double rate){ super(name,year,month,day); this.monthSalary=monthSalary; this.rate=rate; }
double getSalary(int month){
double salary=monthSalary*rate; if(month==this.month){ salary+=100; }
return salary;
}
}
public class company { static void getSalary(int month,ColaEmployee c){
System.out.println(month+\月\+c.name+\
的
\+c.getSalary(month)); }
}
public class TestCompany { public static void main(String[] args) { ColaEmployee a[]=new ColaEmployee[3];
a[0]=new SalariedEmp(\,1990,1,16,3500);
a[1]=new HourlyEmplo(\,1990,12,21,8,240);
a[2]=new SalesEmployee(\,1990,1,12,2000,1.5); for(ColaEmployee c:a){ company.getSalary(1,c); } } }
11 package test2;
public class person { String name; int age;
double height;
person(){}
public person(String name,int age,double height){ this.name=name; this.age=age;
this.height=height;
工
资
: