• 上机作业5.14


    package tth;
    
    public class Vehicle {
        private String brand;
        private String color;
        private speed=0;
        public String getBrand() {
            return brand;
        }
        public void setBrand(String brand) {
            this.brand = brand;
        }
        public String getColor() {
            return color;
        }
        public void setColor(String color) {
            this.color = color;
        }
        public double getSpeed() {
            return speed;
        }
        public void setSpeed(double speed) {
            this.speed = speed;
        }
        public void run(){
            System.out.println("一辆"+this.color+"的"+this.brand+"以"+this.speed+"的速度跑");
        }    
    }
    package tth;
    
    public class VehicleTest {
    
        public static void main(String[] args) {
            Vehicle c=new Vehicle();
            c.brand="benz";
            c.color="black";
            c.run();
        }
    }
    
    package tth;
    
    public class Car extends Vehicle{
        int loader;
    
        public int getLoader() {
            return loader;
        }
    
        public void setLoader(int loader) {
            this.loader = loader;
        }
        public void run(){
            System.out.println("一辆"+this.color+"载客数为"+this.loader+"的"+this.brand+"以"+this.speed+"的速度跑");
        }
    }
    
    package tth;
    
    public class Test {
    
        public static void main(String[] args) {
            Car c=new Car();
            c.brand="Honda";
            c.color="red";
            c.loader=2;
            c.run();
        }
    }
    

      

    package tth;
    
    public abstract class Shape {
        private double area;
        private double per;
        private String color;
    
        public Shape() {
        }
    
        public Shape(String color) {
            this.color = color;
        }
    
        public abstract void getArea();
    
        public abstract void getPer();
    
        public abstract void showAll();
    
    }
    package tth;
    
    public class Rectangle extends Shape {
        double width;
        double height;
    
        public Rectangle() {
        }
    
        public Rectangle(double width, double height, String color) {
            super();
            this.width = width;
            this.height = height;
            this.color = color;
        }
    
        public void getArea() {
            area = width * height;
        }
    
        public void getPer() {
            per = (width + height) * 2;
        }
    
        public void showAll() {
            System.out.println("矩形面积为:" + area + ",周长为:" + per + ",颜色:" + color);
        }
    }
    
    package tth;
    
    public class Circle extends Shape {
        double radius;
    
        public Circle() {
        }
    
        public Circle(double radius, String color) {
            this.color = color;
            this.radius = radius;
        }
    
        public void getArea() {
            area = radius * radius * 3.14;
        }
    
        public void getPer() {
            per = 2 * radius * 3.14;
        }
    
        public void showAll() {
            System.out.println("圆的面积为:" + area + ",周长为:" + per + ",颜色:" + color);
        }
    }
    package tth;
    
    public class PolyDemo {
    
        public static void main(String[] args) {
            Shape a1 = new Circle(5, "pink");
            Shape a2= new Rectangle(9, 10, "red);
            a1.getArea();
            a1.getPer();
            a1.showAll();
            a2.getArea();
            a2.getPer();
            a2.showAll();
        }
    
    }
    

      

  • 相关阅读:
    用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。
    用一条SQL语句显示所有可能的比赛组合
    查询表A中存在ID重复三次以上的记录
    统计numpy数组中最频繁出现的值
    有两个表A和B,均有key和value两个字段,如果B的key在A中也有,就把B的value替换为A中对应的value
    距离和相似度
    NumPy 中的集合运算
    模式识别、机器学习傻傻分不清?给我三分钟!
    NTP服务器方案介绍
    NTP网络时钟原理及应用
  • 原文地址:https://www.cnblogs.com/dayttt/p/12888788.html
Copyright © 2020-2023  润新知