[简答题]
阅读以下说明和Java源程序,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序能够计算三角形、矩形和正方形的周长并输出。
程序由5个类组成:AreaTest是主类,类Triangle、Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算周长的抽象方法。
【程序】
public class girthTest{
public static void main (String args[]){
Figure[]figures={
new
Triangle (2,3,3),new Rectangle(5,8),new Square(5)
};
for(int
i=0;i<figures.length;i++){
System.out.println(figures[i]+"girth="+figures[i].getGirth( ));
}
}
}
public abstract class Figure{
public
abstract double getGirth( );
}
public class
Rectangle extends (1) {
double
height;
double width;
public Rectangle(double height,double width){
this.height=height;
this.width=width;
}
public String toString( ){
return "Rectangle:height="+height+",width="+width+":";
}
public double getGirth( ){
return (2) ;
}
}
[填空题]阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内。
[说明]
下面程序实现十进制向其它进制的转换。
[Java程序]
ClasS Node{
int data;
Node next;
}
class Transform{
private Node top;
public void print( ){
Node p;
while(top!=null){
P=top;
if(P.data>9)
System.out.print((char)(P.data+55));
else
System.out.print(p.data);
top=p.next;
}
}
public void Trans(int d,int i){//d为数字;i为进制
int m;
(1) n=false;
Node p;
while(d>0){
(2) ;
d=d/i;
p=new Node( );
if( (3) ){
p.data=m;
(4) ;
top=P;
n=true;
}
else{
p.data=m;
(5) ;
top=P;
}
}
}
}
[填空题]阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内。
[说明]
下面程序实现十进制向其它进制的转换。
[Java程序]
ClasS Node
int data;
Node next;class Transform
private Node top;
public void print( )
Node p;
while(top!=null)
P=top;
if(P.data>9)
System.out.print((char)(P.data+55));
else
System.out.print(p.data);
top=p.next;
public void Trans(int d,int i)//d为数字;i为进制
int m;
(1) n=false;
Node p;
while(d>0)
(2) ;
d=d/i;
p=new Node( );
if( (3) )
p.data=m;
(4) ;
top=P;
n=true;
else
p.data=m;
(5) ;
top=P;
[填空题]阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内。
[说明]
下面程序是为汽车市场编制的一个程序的一部分。其中automobile是基类。
[Java程序]
class MainJava
public static void main(String agr[])
car sedan=new car( );
sedan.initialize(24,20.0,4);
System.out.println ("The sedan can travel"
+ (1) +"miles./n");
System.out.println ("The sedan has"
+ (2) +"doors./n");
class automobile
protected int miles_per_gallon; //汽车每加仑行驶公里数
(3) double fuel_capacity; //油箱容积
public void initialize(int in_mpg,int in_fuel)
miles_per_galion=in_mpg;
fuel_capacity=in_fuel;
public int get_mpg( )//提供一辆特定汽车每加仑公里数
return miles_per_gallon;
public double get_fuel( )//提供油箱容积
return fuel_capacity;
public double travel_distance( )//计算满油箱情况下的可行驶总公里数
return (4) ;
class car (5)
private int Total_doors;
public void initialize(int in_mpg
[填空题]
阅读以下说明和Java程序代码,将应填入(n)处的字句写在答题纸的对应栏内。
[说明]
在下面的Java程序代码中,类SalesTicket能够完成打印票据正文的功能,类
HeadDecorator与FootDecorator分别完成打印票据的抬头和脚注的功能。己知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。
这是票据的抬头!
这是票据正文!
这是票据的脚注!
---------------------------------------
这是票据的抬头!
这是票据的脚注!
[Java程序代码]
public class
SalesTicket{
public void printTicket( ){
System.out.println("这是票据正文!");
}
}
public class Decorator
extends SalesTicket{
SalesTicket ticket;
public Decorator(SalesTicket t){
ticket =t;
}
public void printTicket( ){
if(ticket!=null)
ticket. printTicket( );
}
}
public class HeadDecorator extends Decorator{
public HeadDecorator(SalesTicket t){
(1) ;
}
public void printTicket( ){
System.out.rintln("这是票据的抬头!");
Super.printTicket( );
}
}
public class FootDecorator extends
Decorato
[简答题]
阅读以下说明和Java程序代码,将应填入
(n) 处的字句写在对应栏内。
1.SMTP是发送E-mail的协议,常用以下5条命令发送E-mail:
HELO,与SMTP服务器握手,传送本机域名;
MAILFROM:,传送发信者的信箱名称;
RCPTTO:,传送接收者的信箱名称;
DATA,发送邮件数据(包括信头和信体);
QUIT,退出与SMTP服务器的连接。
2.试题中直接利用的类及方法如下:
(1)类ServerSocket(int
port)实现TCP服务器接口(socket),它提供两种构造函数,用它们来指定服务器插口所用的端口,并监听到达的连接请求。类中的主要方法有:
accept( ):启动服务器插口监听并等待,直到建立连接为止,一旦建立连接就返回Socket类的一个对象。
getInetAddress( ):返回插口所连接的主机地址。
getLocaIPort(
):返回在服务器插口上建立了连接的端口。
close( ):关闭服务器插口。
(2)类InetAddress包装了Internet地址。类中的主要方法有:
getLocaIHost(
):返回一个代表本机Internet地址的InetAddress对象。
getaddress(
):获得数字表示的IP地址。
getHostName( ):获得域名。
(3)类Socket实现基于连接的客户插口。类中的主要方法有getInetAddress(
):返回一个与插口连接的客户机的Internet地址,其类型为InetAd-dress。getlnputStream(
):用来访问与插口相关的输入流。getOutputStream( ):用来访问与插口机关的输出琉。close( ):关闭插口。
(4)readLine( )是输入流类的一个方法,用于服务器或客户从对方读入一行输入流信息。
(5)用户白