• 上机作业5.14


    package llm;
    
    public abstract class Vehicle {
    	private String brand;
    	private String color;
    	private double speed;
    
    	public Vehicle(String brand, String color) {
    		super();
    		this.brand = brand;
    		this.color = color;
    	}
    
    	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 String getBrand() {
    		return brand;
    	}
    	public void setBrand(String brand) {
    		this.brand =brand;
    	}
    
    	public abstract void run();
    
    }
    package llm;
    
    public class Car extends Vehicle {
    	private int loader;
    
    	public Car(String brand, String color, int loader) {
    		super(brand, color);
    		this.loader = loader;
    	}
    
    	public void run() {
    		System.out.println(getColor() + "色" + getBrand() + "可载" + this.loader + "时速为" + getSpeed() + "米/小时");
    	}
    
    }
    package llm;
    
    public class VehicleText {
    	public static void main(String[] args) {
    		Vehicle car = new Car("Honda", "red", 2);
    		car.run();
    		car.setColor("black");
    		car.setBrand("benz");
    		car.run();	
    		}
    }
    

     

     

    package llm;
    
    public abstract class Shape {
    	protected double area;
    	protected double per;
    	protected String color;
    
    	public Shape() {
    
    	}
    
    	public Shape(String color) {
    		this.color = color;
    	}
    
    	public abstract void getArea();
    
    	public abstract void getPer();
    
    	public abstract void showAll();
    }
    package llm;
    
    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 llm;
    
    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 llm;
    
    public class PolyDemo {
    
    	public static void main(String[] args) {
    		Circle circle = new Circle(4, "red");
    		Rectangle rectangle = new Rectangle(8, 9, "blue");
    		circle.getArea();
    		circle.getPer();
    		circle.showAll();
    		
    		rectangle.getArea();
    		rectangle.getPer();
    		rectangle.showAll();
    
    	}
    
    }
    

      

  • 相关阅读:
    IDEA debug时特慢 Method breakpoints may dramatically slow down debugging
    docker构建镜像
    ubuntu 挂载硬盘
    python 的 flask 、django 、tornado 、sanic
    scrapy实战之scrapyrt的使用
    scrapy框架集成http
    python3之Splash
    CentOS7安装PostgreSQL9.6(图文详细操作)
    替代Navicat的数据库操作工具DBeaver
    CentOS 7 安装 Graylog
  • 原文地址:https://www.cnblogs.com/hzpiou/p/12887318.html
Copyright © 2020-2023  润新知