问题 填空题

请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。
题目要求:
下面是整数除法计算的程序,要求在出现异常时能抛出异常信息。
需要考虑两种异常:
①输入非数字除数;
②输入除法分母为零。
该程序运行的3种结果状态如下。
(1)输入两个合法整数时,运行结果如下图所示。


(2)输入非数字除数时,运行结果如下图所示。


(3)输入除数为零时,运行结果如下图所示。


源程序:
import java.text.DecimalFormat;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Java_3 extends (1) implements ActionListener
private JTextField input1, input2, output;
private int number1, number2;
private double result;
//初始化
public Java_3()
(2) ("示范异常");
Container c=getContentPane();
c.setLayout(new GridLayout(3, 2));
c.add(new JLabel("输入分子", SwingConstants.RIGHT));
input1=new JTextField(10);
c.add(input1);
c.add(new JLabel("输入分母和回车", SwingConstants.RIGHT));
input2=new JTextField(10);
c.add(input2);
input2.addAetionListener(this);
c.add(new JLabel("计算结果", SwingConstants.RIGHT));
output=new JTextField();
c.add(output);
setSize(425, 100);
show();

//处理GUI事件
public void actionPerformed(ActionEvent e)
DeeimalFormat precision3=new DecimalFormat("0.000");
output.setText(""); //空的JTextField输出
(3)
number1=Integer.parseInt(input1.getText());
number2=Integer.parseInt(input2.getText());
result=quotient(number1, number2);
output.setText( (4) );
catch(NumberFormaLException nfe)
JOptionPane.showMessageDialog(this, "你必须输入两个整数", "非法数字格式" , JOptionPane.ERROR_MESSAGE);
catch(Exception dbze)
(5) (this, "除法异常" , "除数为零" , JOptionPane. ERROR_MESSAGE);


//定义求商的方法,如遇除数为零时,能抛出异常
public double quotient(int numerator, int denominator)
throws Exception
if(denominator==0)throw new Exception();
return(double)numerator/denominator;

public static void main(String args[])
Java_3 app=new Java_3();
app.addWindowListener(new windowAdapter()
public void windowClosing(WindowEvent e)
e.getWindow().dispose();
System.exit(0);


);


/*JOptionPane类的常用静态方法如下:
showInputDialog()
showConfirmDialog()
showMessageDialog()
showoptionDialog()
*/

答案

参考答案:precision3.format(result)

解析: 由程序的输出结果看出,输出结果经过了格式化,上面程序也定义了precision3来对结果进行格式化,所以在输出结果时需要对results进行格式化。

选择题
听力题

单词拼写(共20小题, 每小题1分,满分20分)

76. You can’t turn your dream into r__________ if you just sit there and watch TV all day.

77. A good command (运用能力;掌握) of English e__________ you to communicate with foreign businessmen freely.

78. He missed the bus as a r__________ of getting up too late this morning.

79. It is time for us to take m__________ to stop air pollution in our city now.

80. Cycling is highly b__________ to health and the environment.

81. He seems to have __________ (忽视,忽略) one important fact.

82. I believe the house was __________ (故意地) set fire to, not accidentally.

83. She is so __________ (固执的) that she never listens to other people’s advice.

84. Her tears __________ (流动) freely down her cheeks the moment she heard the sad news.

85. They entered the country __________ (非法地).

86. On this __________, however, it had slowed down considerably.

87. “At the time the murder was __________, I was traveling on the 8 o’clock train to London,” said the man.

88. Six men have been __________ in a mine for seventeen hours.

89. They have been told that rescue operations are __________ smoothly.

90. A pilot noticed a __________ which seemed to be making for a Royal Air Force Station nearby.

91. We had to __________ for hours to get in and there must have been several hundred people present just before the show began.

92. He was obviously very nervous and for some minutes stood __________ before the microphone.

93. Oil rigs have to be repaired frequently and divers, who often have to work in darkness a hundred feet under water, have been frightened out of their __________ by giant fish bumping into them as they work.

94. He said that someone might be spying on the station and the pilot was ordered to keep __________ of the strange object.

95. “So do I,” answered the policeman in the same __________.