zoukankan      html  css  js  c++  java
  • 十一周上机

    public  class Vehicle {
    public String brand;
    public String color;
    public double speed=0;
    void setVehicle(String brand,String color) {
        this.brand=brand; 
        this.color=color;    
    }
    void access(String brand,String color,double speed) {
        this.brand=brand;
        this.color=color;
        this.speed=speed;
    }
    void run() {
        System.out.println("该汽车的品牌为:"+this.brand+"颜色为:"+this.color+"速度为"+this.speed);
    }
    }
    复制代码
    复制代码
    public class VehicleTest {
    public static void main(String args[]) {
        Vehicle c;
        c=new Vehicle();
        c.setVehicle("benz", "yellow");
        c.run();
        c.access("benz", "black", 300);
        c.run();
    }
    }
    复制代码
    复制代码
    public class Car extends Vehicle {
        int loader;
        void access(String brand,String color,double speed,int loader) {
            this.brand=brand;
            this.color=color;
            this.speed=speed;
            this.loader=loader;
        }
        void run() {
            System.out.println("该汽车的品牌为:"+this.brand+"颜色为"+this.color+"速度为"+this.speed+"核载人数"+this.loader);;
        }
    }
    复制代码
    复制代码
    public class Test {
    public static void main(String args[]) {
        Car c;
        c=new Car();
        c.access("Honda", "red", 300, 2);
        c.run();
    }
    }
    package pika;
    
    public abstract class Shape {
        private double area;
        private double per;
        private String color;
        public Shape() {
            super();
        }
        public Shape(String color) {
            super();
            this.color = color;
        }
        public abstract double getArea() ;
    
        public abstract double getPer();
    
        public abstract String showAll() ;
        
        public void getColor(String color) {
            this.color=color;
        }
        
    }
    复制代码
    复制代码
    package pika;
    
    public class Rectangle extends Shape{
        private int Width;
        private int height;
        
        public Rectangle() {
            super();
        }
    
        public Rectangle(int width, int height ,String color) {
            super();
            Width = width;
            this.height = height;
            
        }
    
        @Override
        public double getArea() {
            // TODO Auto-generated method stub
            return 0;
        }
    
        @Override
        public double getPer() {
            // TODO Auto-generated method stub
            return 0;
        }
    
        @Override
        public String showAll() {
            // TODO Auto-generated method stub
             String a ="周长是"+(Width+height)*2+"面积是"+Width*height;
            return a;
        }
    
    }
    复制代码
    复制代码
    package pika;
    
    public class Circle extends Shape {
        private int radius;
        
        public Circle(int radius) {
            super();
            this.radius = radius;
        }
    
        public Circle(String color) {
            super();
        }
    
        @Override
        public double getArea() {
            // TODO Auto-generated method stub
            return radius*radius*3.14;
        }
    
        @Override
        public double getPer() {
            // TODO Auto-generated method stub
            return 2*3.14*radius;
        }
    
        @Override
        public String showAll() {
            // TODO Auto-generated method stub
            String a ="周长是"+2*3.14*radius+"面积是"+radius*radius*3.14;
            return a;
        }
        
    }
    复制代码
    复制代码
    package pika;
    
    public class hello {
        public static void main(String[] args) {
            Circle c = new Circle(5);
            Rectangle r = new Rectangle(5,5,"baise");
            System.out.println(c.showAll());
            System.out.println(r.showAll());
        }
    }
  • 相关阅读:
    第一次作业
    第五次作业
    第三次作业
    第六次作业
    第二次作业
    scikitlearn学习 决策树
    [阅读]Think Python CH3 Functions
    [阅读]Think Python CH2 Variables, Expressions, and Statements
    [阅读]Think Python CH1 The Way of the Program
    Hive操作符和函数
  • 原文地址:https://www.cnblogs.com/SmileMRzhang/p/12888312.html
Copyright © 2011-2022 走看看