zoukankan      html  css  js  c++  java
  • 2020.8.17

    一、今日学习内容

    例题验证:

       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+"\t姓名:"+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、定义一个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+"\t体重:"+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 }
    复制代码

    二、遇到的问题

          无。

    三、明日计划

          明天继续完成相关例题的验证。

  • 相关阅读:
    Hibernate 学习-3
    Hibernate反向工程使用心得
    MyEclipse中自动整合Spring3+Hibernate/JPA
    jsp页面不显示问题
    jstl获取当前系统时间的方法
    js实现12小时时钟
    从servlet跳到jsp页面,并用jstl 进行判断和显示方法
    jsp调用js文件时出现乱码
    常见异常总结
    js实现表单验证
  • 原文地址:https://www.cnblogs.com/marr/p/13580199.html
Copyright © 2011-2022 走看看