面向对象机考指南
目录Eclipse使用调字体大小Ptg to JavaBean解决控制台消失问题第三题大题控制台Window —> Preferences搜索font点击Color and Fonts找到Java展示字体这个这个即可调节字体大小生成 空参构造 带参构造 getter setter方法SourceWindow -> Show View -> Console测试类抽象类 父类 Vechicle子类 T
·
目录
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;
}
//必须重写父类中的抽象方法
@Override
public double rent(int day) {
// TODO Auto-generated method stub
return getPerRent()*day;
}
@Override
public void show() {
// TODO Auto-generated method stub
System.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;
}
//必须重写父类中的抽象方法
@Override
public double rent(int day) {
// TODO Auto-generated method stub
return getPerRent()*day;
}
@Override
public void show() {
// TODO Auto-generated method stub
System.out.print(this.getNum()+","+this.getBrand()+","+this.getPerRent()+","+this.getSeat());
}
}
控制台

最后祝大家考试顺利!
更多推荐

所有评论(0)