想要化简一下代码,该如何实现?希望能具体点
import java.util.Scanner;
abstract class Plane {
int jy;
int js;
float wy;
int hc;
int psg;
// 如果要用以下的构造方法,在主方法中如何调用输入?
// public Plane(int jy, int js, float wy, int hc, int psg) {
// super();
// this.jy = jy;
// this.js = js;
// this.wy = wy;
// this.hc = hc;
// this.psg = psg;
// }
public abstract void display();
}
class Fighter extends Plane {
public void display() {
System.out.println("This is a fighter!");
}
private int dd;
public void setDd(int dd) {
this.dd = dd;
}
public int getDd() {
return dd;
}
@Override
public String toString() {
return jy + " " + js + " " + wy + " " + hc + " " + psg + " " + dd;
}
}
class Bomber extends Plane {
public void display() {
System.out.println("This is a bomber!");
}
private int zd;
public void setZd(int zd) {
this.zd = zd;
}
public int getZd() {
return zd;
}
public String toString() {
return jy + " " + js + " " + wy + " " + hc + " " + psg + " " + zd;
}
}
public class oj1417 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
Fighter fit = new Fighter();
Bomber bmb = new Bomber();
while (sc.hasNext()) {
char c = sc.next().charAt(0);
if (c == 'f') {
// fit.jy = sc.nextInt();
// fit.js = sc.nextInt();
// fit.wy = sc.nextFloat();
// fit.hc = sc.nextInt();
// fit.psg = sc.nextInt();
// fit.setDd(sc.nextInt());
// 想要省去上面繁琐的fit.对象,下面的形式该如何实现?
Plane p2 = new Fighter();
p2.Plane(sc.nextInt(),sc.nextInt(),sc.nextFloat(),sc.nextInt(),sc.nextInt());
fit.display();
System.out.println(fit);
}
if (c == 'b') {
bmb.jy = sc.nextInt();
bmb.js = sc.nextInt();
bmb.wy = sc.nextFloat();
bmb.hc = sc.nextInt();
bmb.psg = sc.nextInt();
bmb.setZd(sc.nextInt());
bmb.display();
System.out.println(bmb);
}
}
sc.next();
}
}