步骤:
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:申请域名、网页空间、营销软件、网站建设、善左网站维护、网站推广。
依点击windows--preferences--java --installed JREs
界面右边选jre点击edit按钮
弹界面点击add external JARs按钮选择jdk安装路径rt.jar包般%java_home%\jre\lib\路径点击确定完eclipse查看jdk类库源代码操作步骤图所示:
Eclipse查看Java类库源代码通Ctrl+鼠标左键式完;载JDK并安装候src.zip文件文件Java类库源码候现源码未找问题通其设置解决!
sun公司(现在是oracle公司)提供的java(jdk,jre)都是编译过后class打包文件给大家用的,因为java是开源平台,官方也提供了编译前的代码,供大家参考与学习,这样的代码就是java源代码了。
个人见解,仅供参考。
每天有时间的话 , 会回答一两个图形界面的问题, 但是分数最好还是高点才有兴趣.
具体代码和详细的注释如下
员工类
public class Emp {
private int num;//工号
private String name;//姓名
private double basicPay;//基本工资
private double meritPay;//绩效工资
public Emp(){//无参数构造器
}
public Emp(int num, String name, double basicPay, double meritPay) {//有参数构造器
super();
this.num = num;
this.name = name;
this.basicPay = basicPay;
this.meritPay = meritPay;
}
//重写Object的toString 方法
public String toString() {
return "工号:"+num+"\t姓名:"+name+"\t基本工资:"+basicPay+"\t绩效工资"+meritPay;
}
//下面是属性的set和get
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBasicPay() {
return basicPay;
}
public void setBasicPay(double basicPay) {
this.basicPay = basicPay;
}
public double getMeritPay() {
return meritPay;
}
public void setMeritPay(double meritPay) {
this.meritPay = meritPay;
}
}
输入界面类
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class EmpFrome extends JFrame implements ActionListener {
JTextField jtfnum, jtfname, jtfbp, jtfmp;
JButton jbwtf;
public EmpFrome() {
JLabel jl1 = new JLabel("工号");
jtfnum = new JTextField(8);
add(jl1);
add(jtfnum);
JLabel jl2 = new JLabel("姓名");
jtfname = new JTextField(8);
add(jl2);
add(jtfname);
JLabel jl3 = new JLabel("基本工资");
jtfbp = new JTextField(8);
add(jl3);
add(jtfbp);
JLabel jl4 = new JLabel("绩效工资");
jtfmp = new JTextField(8);
add(jl4);
add(jtfmp);
JLabel jl5 = new JLabel();
jbwtf = new JButton("写入文件");
jbwtf.addActionListener(this);
add(jl5);
add(jbwtf);
setLayout(new GridLayout(5, 2));
setTitle("员工信息录入");
setSize(290, 230);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("写入文件")) {
try{
//获取数据
int num = Integer.parseInt(jtfnum.getText().trim());
String name = jtfname.getText().trim();
double bp = Double.parseDouble(jtfbp.getText().trim());
double mp = Double.parseDouble(jtfmp.getText().trim());
Emp emp = new Emp(num, name, bp, mp);
writeToFile(emp);
JOptionPane.showMessageDialog(this, "录入成功");//提示成功
//清空文本框
jtfnum.setText("");
jtfname.setText("");
jtfbp.setText("");
jtfmp.setText("");
}catch(Exception ex){
//当输入不符合规范时 , 提示错误
JOptionPane.showMessageDialog(this, "请输入正确的数据:\n工号整型,工资浮点型","录入错误",JOptionPane.ERROR_MESSAGE);
}
}
}
//定义的文件路径
final static String FILE_PATH = "employee.dat";
public void writeToFile(Emp emp) {//IO操作,追加写入
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter(new File(FILE_PATH), true));//为true表示追加
bw.write(emp.toString());//写入员工信息
bw.newLine();//换行
} catch (IOException e) {
e.printStackTrace();
}finally{
if(bw!=null){
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
测试类
public class EmpTest {
public static void main(String[] args) {
new EmpFrome();
}
}
测试效果
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class GradeStatistic {
public static void main(String[] args) {
GradeStatistic gs = new GradeStatistic();
ListMark list = new ArrayListMark();
float sum = 0;
while(true){
Scanner sc = new Scanner(System.in);
System.out.print("Please input student name: ");
String name = sc.nextLine();
if(name.equals("end")){
break;
}
System.out.print("Please input student score: ");
float score = sc.nextFloat();
sum += score;
list.add(gs.new Mark(name, score));
}
float max = list.get(0).getScore();
float min = list.get(0).getScore();
for(Mark mark: list){
if(max mark.getScore()){
max = mark.getScore();
}
if(min mark.getScore()){
min = mark.getScore();
}
}
float average = sum / list.size();
System.out.println("Average is: " + average);
System.out.println("Max is: " + max);
System.out.println("Min is: " + min);
}
private class Mark{
private String name;
private float score;
public Mark(String name, float score){
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public float getScore() {
return score;
}
}
}
----------------------
Please input student name: Zhang san
Please input student score: 100
Please input student name: Li Si
Please input student score: 91
Please input student name: Ec
Please input student score: 35
Please input student name: ma qi
Please input student score: 67
Please input student name: end
Average is: 73.25
Max is: 100.0
Min is: 35.0
您好,写了一个程序,求素数,并将所有素数存到ArrayList sushu中:
import java.util.ArrayList;
import java.util.zip.Inflater;
public class sushu {
public static void main(String[] args) {
int n=50,b=0;
float a=0,c=0;
ArrayList sushu=new ArrayList();
for(int i=3;i=n;i++){
int state=0;
for(int j=2;j(i/2+1);j++){
a=(float)i/(float)j;
//System.out.println(a);
b=(int)a;
//System.out.println(a-b);
c=a-b;
//System.out.println(c);
if(c==0){state=1;break;}
}
if(state==0)sushu.add(i);
}
System.out.println(sushu);
}
}
输出结果为:[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]