第十四次JAVA作业
Posted 小忽悠1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十四次JAVA作业相关的知识,希望对你有一定的参考价值。
public class Vehicle { private String brand; private String color; private double speed; 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 Vehicle() { super(); } public Vehicle(String brand, String color, Double speed) { super(); this.brand = brand; this.color = color; this.speed = 0; } public void run(){ System.out.println(brand+"牌的"+color+"车正在以"+speed+"速度奔跑"); } }
package car; public class car extends Vehicle { private int loader; public car() { super(); } public car(String brand, String color, Double speed,int loader) { super(brand, color, speed); // TODO Auto-generated constructor stub } public int getLoader() { return loader; } public void setLoader(int loader) { this.loader = loader; } public void run() { System.out.println( getBrand()+"牌的"+getColor()+"车正在以"+getSpeed()+"速度奔跑"+"承载几人"+getLoader()); } }
package car; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub Vehicle a = new Vehicle(); a.setBrand("benz"); a.setColor("black"); a.run(); car c=new car(); c.setBrand("Honda"); c.setColor("rad"); c.setLoader(2); c.run(); } }
package bb; public class Shape { private double area; private double per; private String color; public double getArea() { return area; } public void setArea(double area) { this.area = area; } public double getPer() { return per; } public void setPer(double per) { this.per = per; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public Shape() { super(); } public Shape(String color) { super(); this.color = color; } public Shape(double area, double per, String color) { super(); this.area = area; this.per = per; this.color = color; } public void showAll() { } public void fetColor() { } public void getcolor() { System.out.println("该图形颜色是"+color); } }
package bb; public class Rectangle extends Shape { private double Width; private double height; public Rectangle() { super(); } public Rectangle(double width, double height, String color) { super( color); Width = width; this.height = height; } public Rectangle(String color) { super(color); // TODO Auto-generated constructor stub } public double getWidth() { return Width; } public void setWidth(double width) { Width = width; } public double getHight() { return height; } public void setHight(double hight) { this.height = hight; } public double getArea() { return Width*height; } public double getPer() { return (Width+height)*2; } public void showAll() { System.out.println("该矩形的面积是"+getArea()+"周长是"+getPer()); }
}
package bb; public class Circle extends Shape { private double radius; public Circle() { super(); } public Circle(double radius, String color) { super(color); this.radius = radius; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } public double getArea() { return radius*radius*3.14; } public double getPer() { return 2*3.14*radius; } public void showAll() { System.out.println("这个圆的面积是"+getArea()+",周长是"+getPer()); } }
package bb; public class Test1 { public static void main(String[] args) { // TODO Auto-generated method stub Rectangle a=new Rectangle(3.5,5.5,"black"); a.showAll(); a.getcolor(); Circle b=new Circle(5.6,"rad"); b.showAll(); b.getcolor(); } }
以上是关于第十四次JAVA作业的主要内容,如果未能解决你的问题,请参考以下文章