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());
        }
    }
  • 相关阅读:
    贪心+stack Codeforces Beta Round #5 C. Longest Regular Bracket Sequence
    暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table
    DFS Codeforces Round #299 (Div. 2) B. Tavas and SaDDas
    二分搜索 Codeforces Round #299 (Div. 2) C. Tavas and Karafs
    水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas
    数学 2015百度之星初赛2 HDOJ 5255 魔法因子
    贪心/数学 2015百度之星资格赛 1004 放盘子
    模拟 2015百度之星资格赛 1003 IP聚合
    rails安装使用版本控制器的原因。
    ActiveStorage. 英文书Learnrails5.2的案例,看如何放到云上。
  • 原文地址:https://www.cnblogs.com/SmileMRzhang/p/12888312.html
Copyright © 2011-2022 走看看