【每日日报】第九天

1 今天写了Teacher类的程序

 题目要求:

 

 

 

 

 

 

 

  程序源代码:

package Person;
import java.util.Scanner;
public class Ma extends Student{
  public static void main(String[] args)
  {
      char[] s1={'1','3','0','5','0','2','1','9','0','0','0','1','0','1','0','3','3','2'};
      char[] s2={'d','o','u','b','l','e','b','e','s','t'};
      char[] s3={'2','0','1','8','1','2','3','4'};
      char[] s4={'铁','1','8','0','1'};
      double value=60.67;
      Student stu1=new Student(s1,s2,s3,s4,value);
      stu1.show();
      Student stu2=new Student(stu1);
      Scanner input = new Scanner(System.in);
      String s;
      s = input.nextLine();
      s3 = s.toCharArray();
      s = input.nextLine();
      s4 = s.toCharArray();
      value = input.nextDouble();
      stu2.setSNo(s3);
      stu2.setClassName(s4);
      stu2.show();
      Teacher t1 = new Teacher(s1,s2,s3,s4,value);
      t1.show();
      Teacher t2 = new Teacher(t1);
      t2.setTNo(s3);
      t2.setDepartmentName(s3);
      t2.show();
      input.close();
  }
 }
 
package Person;
public class Person {
     char[] no;                   //身份证号
     char[] name;                //姓名
     Person(){no=null;name=null; System.out.println("Person Constructor run");}
     Person(char[] str1,char[] str2)//有参构造
     {
      this.no=str1;
      this.name=str2;
         System.out.println("Person Constructor run");
     }
     Person(Person p)        //拷贝构造
     {
         no=p.no;
         name=p.name;
         System.out.println("Person CopyConstructor run");
     }
     void show()             //显示Person信息
     {
      System.out.print("No=");
         System.out.print(no);
         System.out.print(",Name=");
         System.out.println(name);
     }
     void setNo(char[] str) { no=str;}        //设置身份证号
     void setName(char[] str){name=str;}        //设置姓名
     char[] getNo() {return no;}               //获取身份证号
     char[] getName() {return name;}             //获取姓名
}
 
package Person;
public class Student extends Person{
 char[] sNo;
    char[] className;
    double score;
    Student(){System.out.println("Student Constructor run");}
    Student(char[] ss1, char[] ss2, char[] ss3,char[] ss4,double vv)                //有参构造函数
    {
     super(ss1,ss2);
        this.sNo=ss3;
        this.className=ss4;
        this.score=vv;
        System.out.println("Student Constructor run");
    }
    Student(Student stu)           //拷贝构造函数
    {  
     super(stu);
     this.sNo=stu.sNo;
     this.className=stu.className;
     this.score=stu.score;
        System.out.println("Student CopyConstructor run");
    }
    void setSNo(char[] SNO){this.sNo=SNO;}
    char[] getSNo(){return this.sNo;}
    void setClassName(char[] CLASSNAME){this.className=CLASSNAME;}
    char[]  getClassName(){return className;}
    void  setScore(double SCORE){this.score=SCORE;}
    double  getScore(){return this.score;}
    void show()
    {
        System.out.print("No=");
        System.out.print(no);
        System.out.print(",Name=");
        System.out.println(name);
        System.out.print("sNo=");
        System.out.print(sNo);
        System.out.print(",ClassName=");
        System.out.print(className);
        System.out.print(",Score=");
        System.out.println(Math.round(score));
    }
}
 
package Person;public class Teacher extends Person{   char[] tNo;   char[] departmentName;
   double wages;
   Teacher(){}
   Teacher(char[] ss1, char[] ss2, char[] ss3,char[] ss4, double X)                //有参构造函数Teacher
     {
      super(ss1,ss2);
         tNo=ss3;
         departmentName=ss4;
         wages=X;
         System.out.println("Teacher Constructor run");
     }
     Teacher(Teacher  tea)          //拷贝构造函数Teacher
     {
      super(tea);
         tNo=tea.tNo;
         departmentName=tea.departmentName ;
         wages=tea.wages;
         System.out.println("Teacher CopyConstructor run");
     }
     void  setTNo(char[] TNO){tNo=TNO;}
     char[] getTNo(){return tNo;}
     void  setDepartmentName(char[] dep) {departmentName=dep; }
     char[]  getDepartmentName(){return departmentName;}
     void  setWages(double wag){wages=wag;}
     double  getWages(){return wages;}
     void show()
     {
      System.out.print("No=");
      System.out.print(no);
      System.out.print(",Name=");
      System.out.println(name);
      System.out.print("TNo=");
      System.out.print(tNo);
      System.out.print(",DepartmentName=");
      System.out.print(departmentName);
      System.out.print(",Wages=");
      System.out.println(Math.round(wages));
     }
}

 运行截图:

 

 

 

 

2 今天了解到java不支持多继承,但可以通过其他方式来实现 class A extends B;class C extends A

 

3 明天继续写习题

posted @ 2020-07-14 10:16  我试试这个昵称好使不  阅读(76)  评论(0编辑  收藏  举报