第十四周作业
Posted 计算机1902佟阳
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十四周作业相关的知识,希望对你有一定的参考价值。
package homework_Package; public class Vehicle { protected String m_Brand; protected String m_Color; protected double m_Speed; public Vehicle(){} public Vehicle(String brand,String color,double speed){ m_Brand=brand; m_Color=color; m_Speed=speed=0.0; } public String getM_Brand(){ return m_Brand; } public void setM_Brand(String sbrand){ m_Brand=sbrand; } public String getM_Color(){ return m_Color; } public void setM_Color(String scolor){ m_Color=scolor; } public double getM_Speed(){ return m_Speed; } public void setM_Speed(double sspeed){ m_Speed=sspeed; } public void run(){ System.out.println(m_Brand+"品牌,"+m_Color+"颜色"+"速度:"+m_Speed); } }
package homework_Package; public class Car extends Vehicle { private int m_Iader; public Car(){} public Car(String brand,String color,double speed,int iader){ m_Brand=brand; m_Color=color; m_Speed=speed; m_Iader=iader; } public int getm_Iader(){ return m_Iader; } public void setm_Iader(int siader){ m_Iader=siader; } public void run(){ System.out.println("一台"+m_Brand+"品牌,"+m_Color+"颜色,"+m_Iader+"核载人数的汽车,在以"+m_Speed+"m/s的速度行驶"); } }
package homework_Package; public class home_Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Car c1=new Car("Hnda","red",300,2); c1.run(); Vehicle v1=new Vehicle("benz","black",100); v1.run(); } }
package protected_Graph_Homework; public abstract class Shape { protected double m_Area; protected double m_Per; protected String m_Clr; public Shape(){} public Shape(String clr){ m_Clr=clr; } public abstract double getM_Area(); public abstract double getM_Per(); public abstract String getM_Clr(); public abstract void showAll(); }
package protected_Graph_Homework; public class Rectangle extends Shape { private double m_Width; private double m_Height; public Rectangle(){} public Rectangle(double height,double width,String clr){ m_Height=height; m_Width=width; m_Clr=clr; } public double getM_Area(){ return m_Area=m_Height*m_Width; } public double getM_Per(){ return m_Per=(m_Height+m_Width)*2; } public String getM_Clr(){ return m_Clr; } public void showAll(){ System.out.println("一个颜色为"+m_Clr+",长度为"+m_Height+",宽度为"+m_Width+",面积为"+getM_Area()+",周长为"+getM_Per()+"的矩形"); } }
package protected_Graph_Homework; public class Circle extends Shape{ private double m_Radius; public Circle(){} public Circle(double radius,String clr){ m_Radius=radius; m_Clr=clr; } public double getM_Area(){ return m_Area=3.14*(m_Radius*m_Radius); } public double getM_Per(){ return m_Per=2.0*3.14*m_Radius; } public String getM_Clr(){ return m_Clr; } public void showAll(){ System.out.println("一个颜色为"+m_Clr+",半径为"+m_Radius+",面积为"+getM_Area()+",周长为"+getM_Per()+"的圆形"); } }
package protected_Graph_Homework; public class shape_Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Rectangle r1=new Rectangle(2.0,3.0,"红色"); r1.showAll(); Circle c1=new Circle(2.0,"黑色"); c1.showAll(); } }
以上是关于第十四周作业的主要内容,如果未能解决你的问题,请参考以下文章