• 上机作业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();
    
    	}
    
    }
    

      

  • 相关阅读:
    行转列 && 字段拆分
    sqlserver 生成随机值
    mysql查询增加自增列
    Graphx二度关系
    IDEA创建scala项目
    kibana安装
    二十五、Hadoop学记笔记————Hive复习与深入
    二十六、Hadoop学习笔记————Hadoop Yarn的简介复习
    二十四、Hadoop学记笔记————Spark的架构
    二十三、Hadoop学记笔记————Spark简介与计算模型
  • 原文地址:https://www.cnblogs.com/hzpiou/p/12887318.html
Copyright © 2020-2023  润新知