2020.8.15

一、今日学习内容

   1、人与学生

 1 //父类:
 2 public class People1 {
 3     protected int age;
 4     protected String name;
 5     People1(){}
 6     People1(int a,String n){
 7         age=a;
 8         name=n;
 9     }
10     public void setValue(int m,String str) {
11         age=m;
12         name=str;
13     }
14     public void display() {
15         System.out.println("年龄:"+age+"	姓名:"+name);
16     }
17 }
18 //子类:
19 public class Student3 extends People1{
20     private int ID;
21     Student3() {}
22     Student3(int a,String str,int id){
23         super(a,str);
24         ID=id;
25     }
26     public void setID(int m) {
27         ID=m;
28     }
29     public void displayID() {
30         System.out.println("学号:"+ID);
31     }
32 
33     public static void main(String[] args) {
34         Student3 x=new Student3();
35         Student3 y=new Student3(19,"Xiao Hong",10011);
36         x.setValue(18, "Li Ming");
37         x.setID(10010);
38         x.display();
39         x.displayID();
40         y.display();
41         y.displayID();
42     }
43 }

  2、

19、定义一个Dog 类,包含了age,weight 等属性,以及对这些属性操作的方法,实现并测试这个类

 1 public class Dog1 {
 2     private int age;
 3     private float weight;
 4     Dog1(){}
 5     Dog1(int a,float b){
 6         age=a;
 7         weight=b;
 8     }
 9     public void setvalue(int a,float b) {
10         age=a;
11         weight=b;
12     }
13     public void display() {
14         System.out.println("年龄:"+age+"	体重:"+weight);
15     }
16 
17     public static void main(String[] args) {
18         Dog1 x=new Dog1(3,15);
19         Dog1 y=new Dog1();
20         y.setvalue(5,18);
21         x.display();
22         y.display();
23     }
24 }

  

   3、设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,根据坐标能计算矩形的面积。

 1 public class Rectangle1 {
 2     private float x1,y1,x2,y2;
 3     Rectangle1(){}
 4     Rectangle1(float a,float b,float c,float d){
 5         x1=a;
 6         y1=b;
 7         x2=c;
 8         y2=d;
 9     }
10     public void output() {
11         System.out.println("左下角点的坐标为:("+x1+","+y1+")");
12         System.out.println("右上角点的坐标为:("+x2+","+y2+")");
13     }
14     public void display() {
15         double area;
16         area=(x2-x1)*(y2-y1);
17         System.out.println("矩形的面积为:"+area);
18     }
19     public static void main(String[] args) {
20         Rectangle1 A=new Rectangle1(1,1,2,3);
21         A.output();
22         A.display();
23     }
24 }

 

二、遇到的问题

      没有遇到问题

三、明日计划

      明天继续完成相关例题

原文地址:https://www.cnblogs.com/wmdww/p/13507668.html