一:

  1. package Date0805.Test03;
  2. /**
  3. * 作者:sakura
  4. * 日期:2022年08月05日 14:24
  5. */
  6. public class test1 {
  7. public static void main(String[] args) {
  8. Person[] person = new Person[3];
  9. person[0] = new Person("kunkun", 90, "唱跳rap");
  10. person[1] = new Person("sakura",20,"架构师");
  11. person[2] = new Person("LF",18,"保安");
  12. for (int i = 0; i < person.length-1; i++) {
  13. for (int j = 0; j < person.length-1-i; j++) {
  14. if (person[j].getAge()>person[j+1].getAge()){
  15. /*int temp = 0;
  16. temp = person[j].getAge();
  17. person[j].setAge(person[j+1].getAge());
  18. person[j+1].setAge(temp);*/
  19. Person temp = new Person();
  20. temp = person[j];
  21. person[j] =person[j+1];
  22. person[j+1] = temp;
  23. }
  24. }
  25. }
  26. for (int i = 0; i < person.length; i++) {
  27. System.out.println(person[i].toString());
  28. }
  29. }
  30. }
  31. class Person{
  32. private String name;
  33. private int age;
  34. private String job;
  35. public Person() {
  36. }
  37. public Person(String name, int age, String job) {
  38. this.name = name;
  39. this.age = age;
  40. this.job = job;
  41. }
  42. public String getName() {
  43. return name;
  44. }
  45. public void setName(String name) {
  46. this.name = name;
  47. }
  48. public int getAge() {
  49. return age;
  50. }
  51. public void setAge(int age) {
  52. this.age = age;
  53. }
  54. public String getJob() {
  55. return job;
  56. }
  57. public void setJob(String job) {
  58. this.job = job;
  59. }
  60. @Override
  61. public String toString() {
  62. return "Person{" +
  63. "name='" + name + '\'' +
  64. ", age=" + age +
  65. ", job='" + job + '\'' +
  66. '}';
  67. }
  68. }

二:

Untitled.png

三:

image.png

四:

image.png

五:

image.png

  1. /**
  2. * 作者:sakura
  3. * 日期:2022年08月05日 21:45
  4. */
  5. public class Test05 {
  6. public static void main(String[] args) {
  7. Employee employee = new Teacher("sakura",5000,30,200);
  8. System.out.println(employee.getYearSal());
  9. Employee employee1 = new Scientist("sakura",18000,80000);
  10. System.out.println(employee1.getYearSal());
  11. }
  12. }
  13. public class Employee {
  14. private String name;
  15. private double salary;
  16. public Employee(String name, double salary) {
  17. this.name = name;
  18. this.salary = salary;
  19. }
  20. public String getName() {
  21. return name;
  22. }
  23. public void setName(String name) {
  24. this.name = name;
  25. }
  26. public double getSalary() {
  27. return salary;
  28. }
  29. public void setSalary(double salary) {
  30. this.salary = salary;
  31. }
  32. public double getYearSal(){
  33. return 12* getSalary();
  34. }
  35. }
  36. public class Teacher extends Employee{
  37. private double classDay;
  38. private double classSal;
  39. public Teacher(String name, double salary, double classDay, double classSal) {
  40. super(name, salary);
  41. this.classDay = classDay;
  42. this.classSal = classSal;
  43. }
  44. public double getClassDay() {
  45. return classDay;
  46. }
  47. public void setClassDay(double classDay) {
  48. this.classDay = classDay;
  49. }
  50. public double getClassSal() {
  51. return classSal;
  52. }
  53. public void setClassSal(double classSal) {
  54. this.classSal = classSal;
  55. }
  56. @Override
  57. public double getYearSal() {
  58. System.out.println("老师"+getName()+"的年工资为:");
  59. return super.getYearSal()+(getClassSal()*getClassDay());
  60. }
  61. }
  62. public class Scientist extends Employee{
  63. private double bonus;
  64. public Scientist(String name, double salary, double bonus) {
  65. super(name, salary);
  66. this.bonus = bonus;
  67. }
  68. public double getBonus() {
  69. return bonus;
  70. }
  71. public void setBonus(double bonus) {
  72. this.bonus = bonus;
  73. }
  74. @Override
  75. public double getYearSal() {
  76. return super.getYearSal()+getBonus();
  77. }
  78. }

六:可以调用那些属性和方法

  1. class Father extends Grand{/父类
  2. String id="001";
  3. private double score;
  4. public void f1(){
  5. //super可以访问哪些成员(属性和方法)?
  6. super.name;
  7. super.g10
  8. //this可以访问哪些成员?
  9. this.id;
  10. this.score;
  11. this.f1();
  12. this.name;
  13. this.g1():
  14. }
  15. }
  16. class Son extends Father{//子类
  17. String name="BB";
  18. pubic void show(){
  19. //uper可以访问哪些成员(属性和方法)?
  20. super.id;
  21. super.f1();
  22. super.name;
  23. super.g1():
  24. //this可以访问哪些成员?
  25. this.name;
  26. this.g10;
  27. this.show();
  28. this.id;
  29. this.f10;
  30. }

七:写出程序结果

  1. class Test{//父类
  2. String name = "Rose";
  3. Test()
  4. System.out.println("Test");
  5. }
  6. Test(String name){
  7. this.name = name;
  8. }
  9. }
  10. class Demo extends Test{//子类
  11. String name="Jack";Demo0 {
  12. super();
  13. System.out.println("Demo");
  14. }
  15. Demo(String s){
  16. super(s);
  17. }
  18. public void testo{
  19. System.out.println(super.name);System.out.println(this.name);
  20. }
  21. public static void main(Stringl] args)
  22. new Demo0.testO;//匿名对象new Demo("john").testo;//匿名
  23. }

八:

九:

image.png

十:

image.png

  1. @Override
  2. public boolean equals(Object o) {
  3. if (this == o){
  4. return true;
  5. }
  6. if (o instanceof Doctor){
  7. Doctor doctor = (Doctor)o;
  8. if (this.getName()==doctor.getName()&&
  9. this.getAge()==doctor.getAge()&&
  10. this.getGender()==doctor.getGender()&&
  11. this.getJob()==doctor.getJob()&&this.getSal()==doctor.getSal()){
  12. return true;
  13. }
  14. }else {
  15. return false;
  16. }
  17. return false;
  18. }

十一:

image.png

十二:

image.png

十三:

image.png

  1. public class Person {
  2. private String Name;
  3. private String Gender;
  4. private int age;
  5. public Person(String name, String gender, int age) {
  6. Name = name;
  7. Gender = gender;
  8. this.age = age;
  9. }
  10. public void play(){
  11. System.out.println("");
  12. }
  13. public String getName() {
  14. return Name;
  15. }
  16. public void setName(String name) {
  17. Name = name;
  18. }
  19. public String getGender() {
  20. return Gender;
  21. }
  22. public void setGender(String gender) {
  23. Gender = gender;
  24. }
  25. public int getAge() {
  26. return age;
  27. }
  28. public void setAge(int age) {
  29. this.age = age;
  30. }
  31. public void printinfo(){
  32. System.out.println();
  33. }
  34. }
  1. public class Student extends Person{
  2. private int stu_id;
  3. public Student(String name, String gender, int age, int stu_id) {
  4. super(name, gender, age);
  5. this.stu_id = stu_id;
  6. }
  7. public void study(){
  8. System.out.println("好好学习");
  9. }
  10. @Override
  11. public void play() {
  12. System.out.println("玩篮球");
  13. }
  14. public int getStu_id() {
  15. return stu_id;
  16. }
  17. public void setStu_id(int stu_id) {
  18. this.stu_id = stu_id;
  19. }
  20. @Override
  21. public void printinfo() {
  22. System.out.println("老师的信息:");
  23. System.out.println("姓名:" + getName() + "\n" + "年龄:" + getAge() + "\n"+ "学号:" + getStu_id());
  24. study();
  25. play();
  26. System.out.println("-----------------------------------------------------------");
  27. }
  28. }
  1. public class Teacher extends Person{
  2. private int work_age;
  3. public Teacher(String name, String gender, int age, int work_age) {
  4. super(name, gender, age);
  5. this.work_age = work_age;
  6. }
  7. public void teach(){
  8. System.out.println("教书育人");
  9. }
  10. @Override
  11. public void play() {
  12. System.out.println("玩象棋");
  13. }
  14. public int getWork_age() {
  15. return work_age;
  16. }
  17. public void setWork_age(int work_age) {
  18. this.work_age = work_age;
  19. }
  20. @Override
  21. public void printinfo() {
  22. System.out.println("老师的信息:");
  23. System.out.println("姓名:" + getName() + "\n" + "年龄:" + getAge() +"\n"+ "工龄:" + getWork_age());
  24. teach();
  25. play();
  26. System.out.println("-----------------------------------");
  27. }
  28. }
  1. public class Test13 {
  2. public static void main(String[] args) {
  3. Person[] person= new Person[4];
  4. person[0] = new Student("tom","男",8,1001);
  5. person[1] = new Student("jack","男",78,365);
  6. person[2] = new Teacher("sa","男",34,56);
  7. person[3] = new Teacher("sak","男",45,54);
  8. for (int i = 0; i < person.length; i++) {
  9. for (int j = 0; j < person.length-1 -i; j++) {
  10. if (person[j].getAge() < person[j+1].getAge()){
  11. Person temp = null;
  12. temp = person[j];
  13. person[j] = person[j+1];
  14. person[j+1] = temp;
  15. }
  16. }
  17. }
  18. for (int i = 0; i < person.length; i++) {
  19. person[i].printinfo();
  20. }
  21. }
  22. }