(1)定义一个Person类{name,age,job},初始化Person对象数组,有三个person对象,并按照age从大到小进行排序,使用冒泡排序
public class Test {
public static void main(String[] args) {
Person[] person = new Person[3];
person[0] = new Person("jack", 18, "it");
person[1] = new Person("karry", 22, "idol");
person[2] = new Person("cyn", 20, "chairman");
//从大到小排序:
for (int i = 0; i < person.length-i; i++) {
for (int j = 0; j < person.length-i-1;j++){
if (person[j].getAge()<person[j+1].getAge()){
Person person1 = new Person("",0,"");
person1 = person[j+1];
person[j+1] = person[j];
person[j] = person1;
}
}
}
for (int i = 0; i < person.length; i++) {
System.out.println(person[i].getName()+"\t"+person[i].getAge()+"\t"+person[i].getJob());
}
}
}
class Person {
private String name;
private int age;
private String job;
public Person(String name, int age, String job) {
this.name = name;
this.age = age;
this.job = job;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
}
(2)编写老师类
(1)要求有属性“姓名name”,“年龄age”,“职称”,“基本工资salary”
(2)编写业务方法,introduce(),实现输出一个教室的信息
(3)编写教师类的三个子类:教授类,副教授类,讲师类。工资级别分别为:教授为1.3,副教授为1.2,讲师类1.1.在三个子类里都重写父类的introduce()方法。
(4)定义并初始化一个老师对象,调用业务方法,实现对象基本信息的后台打印
-
Teacher类:
public class Teacher {
private String name;
private int age;
private String post;
private double salary;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPost() {
return post;
}
public void setPost(String post) {
this.post = post;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public C(String name, int age, String post, double salary) {
this.name = name;
this.age = age;
this.post = post;
this.salary = salary;
}
public void introduce(){
System.out.print("姓名"+name+"\t"+"年龄"+age+"\t"+"职称"+post+"\t"+"工资"+salary);
}
}
-
教授类:
public class A extends Teacher {
private double score;
public A(String name, int age, String post, double salary, double score) {
super(name, age, post, salary);
this.score = score;
}
public void introduce(){
super.introduce();
System.out.println("\t级别"+score);
}
}
.....其余类和教授类一样
测试类:
public class Test{
public static void main(String[] args){
A a = new A("JACK",55,"教授",10000,1.4);
a.introduce();
}
}