问几个java的题

.修改多态实例中的工资系统。使Employee类包含private实例变 量birthday(使用date类)。假设按月发放工资。创建一个 Employee变量数组,该数组存储各个雇员对象的引用。利用循环 结构,多态的计算各个employee对象的工资,如果当月出现某个 employee对象的生日,则将该雇员工资增加100.美元的奖金。
2.利用继承性来创建一个异常超类和多个异常子类。编写一个程 序,以说明超类的catch子句如何捕获子类异常。
3.编写一个模拟硬币的applet.每次用户按下“Toss”按钮,程序 投掷一个硬币。
统计硬币各面出现的次数,并显示结果。程序应该调用不带任何 参数的独立方法flip,如果是硬币正面,则方法返回“true”; 如 果硬币背面,则方法返回“false”.

答得好追加分数呀。。。谢谢 高手们了!

1.

public class Date {
private int month;
private int day;
private int year;

public Date( int theMonth, int theDay, int theYear )
{
month = checkMonth( theMonth );
year = theYear;
day = checkDay( theDay );

System.out.println( "Date object constructor for date " +
toDateString() );

}

private int checkMonth( int testMonth )
{
if ( testMonth > 0 && testMonth <= 12 )
return testMonth;

else {
System.out.println( "Invalid month (" + testMonth +
") set to 1." );
return 1;
}

}

private int checkDay( int testDay )
{
int daysPerMonth[] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
return testDay;

if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||
( year % 4 == 0 && year % 100 != 0 ) ) )
return testDay;

System.out.println( "Invalid day (" + testDay + ") set to 1." );

return 1;

}

public String toDateString()
{
return month + "/" + day + "/" + year;
}

}

3.
方法1:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class No1_Min extends JApplet {
JButton button;
String str="抛硬币:";
public void init(){
button=new JButton("Toss");
Container container=getContentPane();
container.setLayout(new FlowLayout());
container.add(button);
button.addActionListener(
new ActionListener(){
int front=0,back=0;
public void actionPerformed(ActionEvent e){
if (Toss()) front++;
else back++;
str="正面"+front+"次 "+"负面"+back+"次";
showStatus(str);
}//end actionPerformed
}//end ActionListener
);
}//end init

boolean Toss(){
int Num;
Num=1+(int)(Math.random()*2);
if(Num==1)return true;
else return false;
}//end Toss
}//end coin

方法2:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class No1_Min extends JApplet implements ActionListener{
JButton button;
String str;
int front=0,back=0;
public void init(){
button=new JButton("Toss");
Container container=getContentPane();
container.setLayout(new FlowLayout());
container.add(button);
button.addActionListener(this);
}//end init

public void actionPerformed(ActionEvent e){
if (Toss()) front++;
else back++;
str="正面"+front+"次 "+"负面"+back+"次";
showStatus(str);
}//end actionPerformed

boolean Toss(){
int Num;
Num=1+(int)(Math.random()*2);
if(Num==1)return true;
else return false;
}//end Toss
}//end coin
温馨提示:答案为网友推荐,仅供参考
相似回答