📄 custom.java
字号:
package WorkSixteen;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.*;
public class Custom {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int EOF=0;
int count=0;
int Year=0;
int Man_Num=0;
int Woman_Num=0;
int total=0;
String Age=null;
String Sex=null;
String Name=null;
//set date
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
Date d=new Date(System.currentTimeMillis());
//df.format(new Date());
//input year
String input;
input=JOptionPane.showInputDialog("Input year:");
/*while(input!=null)
{
input=JOptionPane.showInputDialog("Error:No year Input! Try again:");
}*/
Year=Integer.parseInt(input);
while(Year<0||Year>99)
{
input=JOptionPane.showInputDialog("Error:Wrong year! Try again:");
Year=Integer.parseInt(input);
}
try{
//file exist?
File dir=new File("C:\\Documents and Settings\\123\\workspace\\homework\\src\\WorkSixteen\\Customer.txt");
if(dir.exists())
{
//open customer file
FileInputStream fis=new FileInputStream("C:\\Documents and Settings\\123\\workspace\\homework\\src\\WorkSixteen\\Customer.txt");
InputStreamReader isr=new InputStreamReader(fis);
BufferedReader br=new BufferedReader(isr);
//open result file
FileOutputStream fos=new FileOutputStream("C:\\Documents and Settings\\123\\workspace\\homework\\src\\WorkSixteen\\Result.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos);
BufferedWriter bw=new BufferedWriter(osw);
//read customer file
String msg=br.readLine();
if(msg==null)
{
EOF=1;
//Error:costomer file is null
JOptionPane.showMessageDialog(null, "Costomer File is NULL", "Error", JOptionPane.ERROR_MESSAGE);
}
//print title
count=0;
bw.write("***屭媞忣曬***"+" "+df.format(d)+'\r'+'\n');
count=count+1;
bw.write(" "+'\r'+'\n');
count=count+1;
bw.write("擭楊"+" "+"惈暿"+" "+"巵柤"+'\r'+'\n');
count=count+1;
//loop
while(EOF!=1)
{
StringTokenizer t=new StringTokenizer(msg,",");
Age=t.nextToken();
Sex=t.nextToken();
Name=t.nextToken();
if(!(Year/10!=(Integer.parseInt(Age)/10)||!Sex.equals("抝")))
{
Man_Num=Man_Num+1;
bw.write(Age+" "+Sex+" "+Name+'\r'+'\n');
count=count+1;
//next page?
if(count>=20)
{
bw.write("***********************************"+'\r'+'\n');
//print title
count=0;
bw.write("***屭媞忣曬***"+" "+df.format(d)+'\r'+'\n');
count=count+1;
bw.write(" "+'\r'+'\n');
count=count+1;
bw.write("擭楊"+" "+"惈暿"+" "+"巵柤"+'\r'+'\n');
count=count+1;
}
}
if(!(Year/10!=(Integer.parseInt(Age)/10)||!Sex.equals("彈")))
{
Woman_Num=Woman_Num+1;
bw.write(Age+" "+Sex+" "+Name+'\r'+'\n');
count++;
//next page?
if(count>=20)
{
bw.write("***********************************"+'\r'+'\n');
//print title
count=0;
bw.write("***屭媞忣曬***"+" "+df.format(d)+'\r'+'\n');
count=count+1;
bw.write(" "+'\r'+'\n');
count=count+1;
bw.write("擭楊"+" "+"惈暿"+" "+"巵柤"+'\r'+'\n');
count=count+1;
}
}
//read customer file
msg=br.readLine();
if(msg==null)
{
EOF=1;
}
}
total=Man_Num+Woman_Num;
//no result
if(total==0)
{
//output Error
JOptionPane.showMessageDialog(null, "No result", "Error", JOptionPane.ERROR_MESSAGE);
}
//next line
bw.write(" "+'\r'+'\n');
count++;
//next page?
if(count>20)
{
bw.write("***********************************"+'\r'+'\n');
//print title
count=0;
bw.write("***屭媞忣曬***"+" "+df.format(new Date(System.currentTimeMillis()))+'\r'+'\n');
count=count+1;
bw.write('\r'+'\n');
count=count+1;
bw.write("擭楊"+" "+"惈暿"+" "+"巵柤"+'\r'+'\n');
count=count+1;
}
bw.write("擭戙"+" "+((Year/10)*10)+"~"+((Year/10)*10+9)+" "+"抝"+" "+Man_Num+"恖"+" "+"彈"+" "+Woman_Num+"恖"+" "+"崌寁"+" "+total+"恖");
br.close();
isr.close();
fis.close();
bw.close();
osw.close();
fos.close();
}
else
{
JOptionPane.showMessageDialog(null, "Costomer File is not exist", "Error", JOptionPane.ERROR_MESSAGE);
}
}catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -