📄 archreport.java
字号:
//package ArchReport;import java.io.*;import java.util.*;/** File Name: ArchReport.java Author: 黄增博 #B02251132 Date: March 20 2004 Description: The ArchReport program reads a series of lines describing finds until the end-of-file is reached, it then generates a report of the deepest item and the closest item to the item on the first line.**/public class ArchReport{ private ArchFind firstFind; //first input time private ClosestFind theClosest; // used to find the closest to first private DeepestFind theDeepest; // finds the deepest item public ArchReport(){ firstFind = null; //initially there are no items theClosest = null; theDeepest = null; } /*reads a series of lines containing archeological finds * searching for the deepest and item closest to the first item. */ public void processInput(BufferedReader input) throws IOException{ /*provide the implementation, you must crate * and use the firstFind, theClosest, and theDeepest objects */ String line=null; double first=0; double second=0; double third=0; String fourth=null; ArchFind temp=null; boolean check=true; while((line=input.readLine())!=null){ int count=0; /*provide the implementation to process the lines*/ StringTokenizer stok = new StringTokenizer(line); while(stok.hasMoreTokens()){ if (count==0)first=Double.parseDouble(stok.nextToken()); if (count==1)second=Double.parseDouble(stok.nextToken()); if (count==2)third=Double.parseDouble(stok.nextToken()); if (count==3)fourth=stok.nextToken(); count++; }//input the stok to four items if(check)//input the firstfind {firstFind=new ArchFind(first,second,third,fourth); theClosest=new ClosestFind(firstFind); theDeepest=new DeepestFind(firstFind); temp=firstFind; check=false; } else //update the closest and the deepest {temp=new ArchFind(first,second,third,fourth); theClosest.update(temp); theDeepest.update(temp); } } } /* generate the report */ public void getReport(){ System.out.println("First: " + firstFind.toString()); System.out.println("Deepest: " + theDeepest.getDeepest().toString()); ArchFind closest = theClosest.getClosest(); if(closest != null){ System.out.println("Closest: " + closest.toString()); } } /*the main program, crates ArchReport and process the standard input */ public static void main(String[] args)throws IOException{ BufferedReader stdin=new BufferedReader( new FileReader("finds.txt")); ArchReport report = new ArchReport(); report.processInput(stdin); report.getReport(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -