目录
Eclipse使用
调字体大小
Ptg to JavaBean
解决控制台消失问题
第三题大题
控制台
Eclipse使用
调字体大小
Window —> Preferences
搜索font
点击Color and Fonts
找到Java
展示字体
这个这个
即可调节字体大小
Ptg to JavaBean
生成 空参构造 带参构造 getter setter方法
Source
解决控制台消失问题
Window -> Show View -> Console
第三题大题
题目
测试类
抽象类 父类 Vechicle
子类 Truck
子类 Bus
全部代码
package Dduo;public class Prog1 {//测试类public static void main(String[] args) {Vechicle[]arr =new Vechicle[4];arr[0]=new Truck();arr[1]=new Truck("J56789","大众",300,5000);arr[2]=new Bus();arr[3]=new Bus("J00001","解放",1000,40);for(int i=0;i<arr.length;i++) {arr[i].show();System.out.println(arr[i].rent(10));}}
}//抽象类 父类 Vechicle
abstract class Vechicle{//成员属性private String num;private String brand;private double perRent;//空参构造 带参构造public Vechicle() {this.num="JB0000";this.brand="红旗";this.perRent=0;}public Vechicle(String num,String brand,double perRent) {this.num=num;this.brand=brand;this.perRent=perRent;}//setter getter方法public String getNum() {return num;}public void setNum(String num) {if(num.length()==6) {this.num=num;}else {this.num="JB0000";}}public String getBrand() {return brand;}public void setBrand(String brand) {this.brand=brand;}public double getPerRent() {return perRent;}public void setPerRent(double perRent) {if(perRent>0) {this.perRent=perRent;}else {this.perRent=0;}}//抽象方法 无方法体public abstract double rent(int day);public abstract void show();}
//子类 Truck
class Truck extends Vechicle{//成员属性private double load;//构造方法public Truck() {super();this.load=10;}public Truck(String num,String brand,double perRent,double load) {super(num,brand,perRent);this.load=load;}//setter getter方法public double getLoad() {return load;}public void setLoad(double load) {this.load=load;}//必须重写父类中的抽象方法@Overridepublic double rent(int day) {// TODO Auto-generated method stubreturn getPerRent()*day;}@Overridepublic void show() {// TODO Auto-generated method stubSystem.out.print(this.getNum()+","+this.getBrand()+","+this.getPerRent()+","+this.getLoad());}}//子类 Bus
class Bus extends Vechicle{private int seat;//空参构造 带参构造public Bus() {super();this.seat=20;}public Bus(String num,String brand,double perRent,int seat) {super(num,brand,perRent);this.seat=seat;}//getter setter方法public int getSeat() {return seat;}public void setSeat(int seat) {this.seat=20;}//必须重写父类中的抽象方法@Overridepublic double rent(int day) {// TODO Auto-generated method stubreturn getPerRent()*day;}@Overridepublic void show() {// TODO Auto-generated method stubSystem.out.print(this.getNum()+","+this.getBrand()+","+this.getPerRent()+","+this.getSeat());}}