安徽财贸职业学院2011—2012学年度第二学期 《Java面向对象程序设计》期末试卷答案(B卷)
适用班级:软件1101
一、单选题
1 2 3 4 5 6 7 8 9 10
C C D D A A B B A D
11 12 13 14 15 16 17 18 19 20
C D B A C C B C A A
21 22 23 24 25 26 27 28 29 30
D D D D B C D C C B
二、填空题
1.JavaSE JavaeE 2.字节码 .class 3.封装 继承
4.抽象(或abstract) final 5.super 6.接口 三、阅读理解题
1.6 3.10.0 2.1 4.a=60 4 b=20 9 c=30 Totle is 14 5.234
四、编程题
1.【1】entends Point 【2】super(a1,b1) 【3】Rec r1=new Rec(0,0,10,20) 2.import java.util.Arrays; public class CharsSort {
public static void main(String[] args) {
char[] chars = new char[]{'a','c','u','b','e','p','f','z'}; System.out.print(\原字符序列:\ for(int i = 0; i < chars.length; i++){ System.out.print(chars[i] + \ } Arrays.sort(chars); //对数组进行升序排序 System.out.print(\升序排序后:\ for(int i = 0; i < chars.length; i++){ System.out.print(chars[i] + \ } System.out.print(\逆序输出为:\ for(int i = chars.length-1; i >= 0; i--){ System.out.print(chars[i] + \ } }
}
3.public abstract class MotoVehicle { private String no;// 汽车牌号 private String brand;// 汽车品牌
第1页 共3页
public MotoVehicle() { }
public MotoVehicle(String no, String brand) { this.no = no; this.brand = brand; }
public String getNo() { return no; }
public String getBrand() { return brand; }
public abstract int calRent(int days); }
public final class Car extends MotoVehicle { private String type;// 汽车型号 public Car() { } public Car(String no, String brand, String type) { super(no, brand); this.type = type; } public String getType() { return type; } public void setType(String type) { this.type = type; } public int calRent(int days) { if (\代表550i return days * 500; } else if (\代表商务舱GL8 return 600 * days; } else { return 300 * days; } }
}
public final class Bus extends MotoVehicle { private int seatCount;// 座位数 public Bus() { }
public Bus(String no, String brand, int seatCount) { super(no, brand); this.seatCount = seatCount; }
public int getSeatCount() { return seatCount; }
public void setSeatCount(int seatCount) { this.seatCount = seatCount; }
public int calRent(int days) { if (seatCount <= 16) {
第2页 共3页
return days * 800; } else { return days * 1500; } } }
import java.util.Scanner; public class TestRent {
public static void main(String[] args) { String no,brand,mtype,type; int seatCount,days,rent; Car car; Bus bus; Scanner input = new Scanner(System.in); System.out.println(\欢迎您来到汽车租赁公司!\ System.out.print(\请输入要租赁的天数:\ days=input.nextInt(); System.out.print(\请输入要租赁的汽车类型(1:轿车 2、客车):\ mtype = input.next(); if(\ System.out.print(\请输入要租赁的汽车品牌(1、宝马 2、别克):\ brand=input.next(); System.out.print(\请输入轿车的型号 \ if(\ System.out.print(\(1、550i):\ else System.out.print(\(2、商务舱GL8 3、林荫大道)\ type=input.next(); no=\京BK5543\简单起见,直接指定汽车牌号 System.out.println(\分配给您的汽车牌号是:\ car =new Car(no,brand,type); rent=car.calRent(days); } else{ System.out.print(\请输入要租赁的客车品牌(1、金杯 2、金龙):\ brand=input.next(); System.out.print(\请输入客车的座位数:\ seatCount=input.nextInt(); no=\京AU8769\简单起见,直接指定汽车牌号 System.out.println(\分配给您的汽车牌号是:\ bus=new Bus(no,brand,seatCount); rent=bus.calRent(days); } System.out.println(\顾客您好!您需要支付的租赁费用是\。\ } }
第3页 共3页