Java与网络程序设计考核要求.docx
《Java与网络程序设计考核要求.docx》由会员分享,可在线阅读,更多相关《Java与网络程序设计考核要求.docx(18页珍藏版)》请在冰点文库上搜索。
![Java与网络程序设计考核要求.docx](https://file1.bingdoc.com/fileroot1/2023-7/21/f17f6e46-6800-4456-a144-2d5bd40072f5/f17f6e46-6800-4456-a144-2d5bd40072f51.gif)
Java与网络程序设计考核要求
姓名:
学号:
班级:
天津师范大学考核要求
2011—2012学年第一学期期末考核要求
科目:
Java与网络程序设计
学院:
计信学院
专业:
计算机科学与技术
题号
一
二
三
四
五
总分
分数
2011-2012
(1)的“Java与网络程序设计”课程为专业选修课,鉴于课程特点,“Java与网络程序设计”课程采用开卷实践考核方式,选修此课程的同学应于第17教学周完成实践考核题目,并上交程序成品、完成答辩。
实践考核题目
独立完成Project1、Project2、Project3和Project4四个项目。
Project1
(1)按照如下UML图要求实现GeometricObject类和Circle类:
(2)修改Circle类,使其实现Comparable接口并覆盖Object类的equals方法,其中实现Comparable接口的Circle类能根据radius数值比较大小,覆盖的equals方法能根据radius数值判定Circle对象是否相等;
(3)编写测试类,创建半径为5和10的Circle对象,显示equals方法和compareTo方法调用结果。
importjava.util.Date;
//编写测试类,创建半径为5和10的Circle对象,显示equals方法和compareTo方法调用结果。
publicclassTest
{
publicstaticvoidmain(String[]args)
{
Circlec1=newCircle(5);
Circlec2=newCircle(10);
System.out.println(c1.equals(c2));
System.out.println(pareTo(c2));
}
}
classGeometricObject
{
privateStringcolor;
privatebooleanfilled;
privateDatedateCreated;
GeometricObject()
{
}
GeometricObject(Stringcolor,booleanfilled)
{
this.color=color;
this.filled=filled;
}
publicStringgetColor(){
returncolor;
}
publicvoidsetColor(Stringcolor){
this.color=color;
}
publicbooleanisFilled(){
returnfilled;
}
publicvoidsetFilled(booleanfilled){
this.filled=filled;
}
publicDategetDateCreated(){
returndateCreated;
}
publicStringtoString()
{
returncolor;//?
?
?
?
?
?
}
publicdoublegetArea()
{
return0;//
}
publicdoublegetPerimeter()
{
return0;//
}
}
classCircleextendsGeometricObjectimplementsComparable
{
privatedoubleradius;
Circle()
{
}
Circle(doubleradius)
{
this.radius=radius;
}
Circle(doubleradius,Stringcolor,booleanfilled)
{
this.radius=radius;
this.setColor(color);
this.setFilled(filled);
}
publicdoublegetRadius()
{
returnradius;
}
publicvoidsetRadius(doubleradius)
{
this.radius=radius;
}
publicdoublegetDiameter()
{
returnthis.radius*2;//直径
}
//实现Comparable接口的Circle类能根据radius数值比较大小
publicintcompareTo(Objecto)
{
if(getRadius()>((Circle)o).getRadius())
return1;
elseif(getRadius()<((Circle)o).getRadius())
return-1;
else
return0;
}
//覆盖的equals方法能根据radius数值判定Circle对象是否相等;
publicbooleanequals(Circlec)
{
if(getRadius()==c.getRadius())
returntrue;
else
returnfalse;
}
}
Project2:
编写程序显示一个饼图,使用饼图显示作业、平时测验、期中考试和期末考试占总成绩的百分比。
假设作业占20%用红色显示,平时测验占10%用蓝色显示,期中考试占30%用绿色表示,期末考试占40%用橙色表示。
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.util.Scanner;
publicclassTest
{
publicstaticvoidmain(String[]args)
{
ZiFrameframe=newZiFrame();
frame.setTitle("饼图");//面板标题
frame.setSize(300,200);//面板大小
frame.setResizable(false);//不能改变面板大小
frame.setLocationRelativeTo(null);//显示器上居中显示
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭操作
frame.setVisible(true);
}
}
classZiFrameextendsJFrame
{
ZiFrame()
{
setLayout(newBorderLayout());
add(newNewJPanel(),BorderLayout.CENTER);
}
}
classNewJPanelextendsJPanel
{
protectedvoidpaintComponent(Graphicsg)
{
super.paintComponent(g);
intxCenter=getWidth()/2;
intyCenter=getHeight()/2;
intradius=(int)(Math.min(getWidth(),getHeight())*0.4);
intx=xCenter-radius;
inty=yCenter-radius;
g.setColor(Color.red);
g.fillArc(x,y,2*radius,2*radius,0,72);
g.setColor(Color.blue);
g.fillArc(x,y,2*radius,2*radius,72,36);
g.setColor(Color.green);
g.fillArc(x,y,2*radius,2*radius,98,108);
g.setColor(Color.white);
g.fillArc(x,y,2*radius,2*radius,206,154);
g.setColor(Color.black);
g.drawString("Projects--20%",3*radius,40);
g.drawString("Quizzes--10%",2*radius,10);
g.drawString("Midterms--40%",0,radius);
g.drawString("Final--40%",2*radius,140);
}
}
Project3:
编写一个程序,计算投资值在给定利率以及给定年数下的未来值。
计算的公式如下所示:
使用文本域显示利率、投资总额和年数。
当用户点击Calculate按钮时,在文本域显示未来的总额。
/*
编写一个程序,计算投资值在给定利率以及给定年数下的未来值。
计算的公式如下所示:
使用文本域显示利率、投资总额和年数。
当用户点击Calculate按钮时,在文本域显示未来的总额。
*/
importjava.awt.Dimension;
importjava.awt.GridLayout;
importjava.awt.Toolkit;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JTextField;
publicclassTest
{
publicstaticvoidmain(String[]args)
{
ZiFrameframe=newZiFrame();
frame.setTitle("投资计算器");//面板标题
frame.setSize(300,200);//面板大小
frame.setResizable(false);//不能改变面板大小
frame.setLocationRelativeTo(null);//显示器上居中显示
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭操作
frame.setVisible(true);//显示面板
}
}
classZiFrameextendsJFrame
{
privateJButtonbtn=newJButton("Calculate");
privateJTextField
tfd1=newJTextField(8),
tfd2=newJTextField(8),
tfd3=newJTextField(8),
tfd4=newJTextField(8);
//privatedoubleinvestmentAmount,years,annualInterestRate;
ZiFrame()
{
setLayout(newGridLayout(5,2,5,5));
add(newJLabel("InvestmentAmount:
"));
add(tfd1);
add(newJLabel("Years:
"));
add(tfd2);
add(newJLabel("AnnualInterestRate:
"));
add(tfd3);
add(newJLabel("Futurevalue:
"));
add(tfd4);
add(newJLabel(""));
add(btn);
btn.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
tfd4.setText(""+Double.parseDouble(tfd1.getText())*
Math.pow((1+Double.parseDouble(tfd3.getText())/1200),Double.parseDouble(tfd2.getText())*12));
}
});
}
}
Project4:
编写一个程序,模拟交通信号灯。
程序让用户从红、黄、绿三色灯中选择一种。
当选择一个单选按钮后,相应的灯被打开,每次只能亮一种灯。
程序开始时所有的灯都不亮。
importjava.awt.BorderLayout;
importjava.awt.Color;
importjava.awt.Graphics;
importjava.awt.GridLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.ButtonGroup;
importjavax.swing.JFrame;
importjavax.swing.JPanel;
importjavax.swing.JRadioButton;
publicclassTest
{
publicstaticvoidmain(String[]args)
{
RadioButtonDemoframe=newRadioButtonDemo();
frame.setTitle("信号灯");//面板标题
frame.setSize(300,200);//面板大小
frame.setResizable(false);//不能改变面板大小
frame.setLocationRelativeTo(null);//显示器上居中显示
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭操作
frame.setVisible(true);
}
}
classRadioButtonDemoextendsJFrame
{
privateJRadioButtonjrbRed,jrbYellow,jrbGreen;
RadioButtonDemo()
{
BorderLayoutblay=newBorderLayout();
setLayout(blay);
JPaneljpRadioButtons=newJPanel();
finalStartJPaneljpRadioLamps=newStartJPanel();
jpRadioButtons.setLayout(newGridLayout(1,3));
jpRadioButtons.add(jrbRed=newJRadioButton("Red"));
jpRadioButtons.add(jrbYellow=newJRadioButton("Yellow"));
jpRadioButtons.add(jrbGreen=newJRadioButton("Green"));
add(jpRadioLamps,BorderLayout.CENTER);
add(jpRadioButtons,BorderLayout.SOUTH);
ButtonGroupgroup=newButtonGroup();
group.add(jrbRed);
group.add(jrbYellow);
group.add(jrbGreen);
//设置热键
jrbRed.setMnemonic('R');
jrbYellow.setMnemonic('Y');
jrbGreen.setMnemonic('G');
jrbRed.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
jpRadioLamps.i=1;
repaint();
}
});
jrbYellow.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
jpRadioLamps.i=2;
repaint();
}
});
jrbGreen.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
jpRadioLamps.i=3;
repaint();
}
});
}
}
classStartJPanelextendsJPanel
{
publicinti=0;
protectedvoidpaintComponent(Graphicsg)
{
super.paintComponent(g);
intxCenter=getWidth()/2;
intyCenter=getHeight()/2;
intradius=(int)(Math.min(getWidth(),getHeight())*0.4);
intx=xCenter-radius;
inty=yCenter-radius;
if(i==0)
{
g.drawRect(xCenter,y,40,120);
g.drawOval(xCenter+2,y+2,35,35);
g.drawOval(xCenter+2,y+42,35,35);
g.drawOval(xCenter+2,y+82,35,35);
}
if(i==1)
{
g.drawRect(xCenter,y,40,120);
g.setColor(Color.red);
g.fillOval(xCenter+2,y+2,35,35);
g.setColor(Color.black);
g.drawOval(xCenter+2,y+42,35,35);
g.drawOval(xCenter+2,y+82,35,35);
}
if(i==2)
{
g.drawRect(xCenter,y,40,120);
g.setColor(Color.yellow);
g.fillOval(xCenter+2,y+42,35,35);
g.setColor(Color.black);
g.drawOval(xCenter+2,y+2,35,35);
g.drawOval(xCenter+2,y+82,35,35);
}
if(i==3)
{
g.drawRect(xCenter,y,40,120);
g.setColor(Color.green);
g.fillOval(xCenter+2,y+82,35,35);
g.setColor(Color.black);
g.drawOval(xCenter+2,y+42,35,35);
g.drawOval(xCenter+2,y+2,35,35);
}
}
}
开发与部署环境要求
JDK1.7
EclipseIndigo
上交内容及格式
将Project1、Project2、Project3和Project4的整个项目文件夹压缩为.rar文件,压缩文件名分别为<学号><姓名>1.rar、<学号><姓名>2.rar、<学号><姓名>3.rar和<学号><姓名>4.rar,如:
学号为06509275的张三同学上交的四个文件应为06509275张三1.rar、06509275张三2.rar、06509275张三3.rar和06509275张三4.rar。
评分标准
每个项目占20分,答辩表现占20分,共计100分。
项目要求能实现需求的全部功能,运行有效,无明显错误;界面友好、美观;代码架构清晰、条理清楚;有必要注释。
答辩要求能独立部署并熟练演示提交的程序;正确回答相关问题。