資源簡介
第二次作業(yè):
1. 編寫點類(Point類),屬性成員有x,y,都是double數(shù)據(jù)類型。需要為Point類編寫構(gòu)造函數(shù)。
編寫直線類(Line類),需要提供兩點確定一條直線的函數(shù)功能。
如果兩點重合,可以返回異常或者返回null引用來解決這個問題。
直線類的數(shù)據(jù)成員和函數(shù)成員請自行設(shè)計。
2. 給定文本文件,文件名稱為a.txt,文件內(nèi)容為一個8行8列的字符矩陣,內(nèi)容為1和0字符,
請編程計算出該矩陣中水平方向或者垂直方向或者斜線方 向連續(xù)1最多的個數(shù)。
例如:
11001101
10110101
01010101
11001000
01010101
11001101
00011000
11110000
3. 編寫程序求出1萬以內(nèi)的所有素數(shù),并將這些素數(shù)輸出到一個文本文件中,每行文本只包含一個素數(shù)數(shù)據(jù)。
該文本文件內(nèi)容要求可以用記事本程序來查看。
4. 編寫程序求出1萬以內(nèi)的所有素數(shù),然后再判斷這些素數(shù)中哪些是由素數(shù)拼接而成的。
例如素數(shù)23就符合條件,23本身是素數(shù),其由素數(shù)2,和素數(shù)3拼接(連接)組成。
素數(shù)29就不滿足條件,2是素數(shù),而9不是素數(shù)。素數(shù)307不滿足條件,不能忽略0.
7907這個素數(shù)符合條件,7是素數(shù),907是素數(shù)。
需要把符合條件的拼接素數(shù)全部輸出,并統(tǒng)計個數(shù)。
5. 要求從控制臺輸入英語單詞及單詞解釋兩項數(shù)據(jù),
把錄入的數(shù)據(jù)追加到文件中。要求提供單詞查詢功能。
用戶輸入單詞后,從單詞庫文件中查找,如果存在則輸出
該單詞的解釋。注意,單詞不能有重復(fù),如果重復(fù)則覆蓋替換
以前的解釋數(shù)據(jù)。
6. 通過命令行參數(shù)輸入一個文件夾的路徑名稱,然后編寫程序找出該文件夾下文件名稱重復(fù)并且文件大小也一樣的文件,
如果沒有“重復(fù)文件”,則輸出“沒有重復(fù)文件”的提示,如果有,需要輸出文件名稱,和文件所在的文件夾路徑(絕對路徑)。
提示,需要遍歷該文件夾下所有子文件夾,設(shè)計一個文件類,屬性包括文件名稱,文件路徑,文件大小,然后進行“重復(fù)”
判斷,如果文件重復(fù),則需要記錄并輸出,有可能有文件名重復(fù),但是文件大小不一樣,重復(fù)的文件可能不止2個,可能
在不同的子文件夾下有多個文件重復(fù)。
7. 霍夫曼編碼實現(xiàn)壓縮文本文件,見文件huffman.rar. 對文件數(shù)據(jù)讀寫等功能已經(jīng)實現(xiàn),程序在Q2Resources.zip中。
Q2Resources.zip中的文件禁止修改。請將TextZip.java文件所有未實現(xiàn)的函數(shù)按照要求給以實現(xiàn)。

代碼片段和文件信息
package?huffman;
public?class?BinaryTree?extends?BinaryTreeBasis?{
??public?BinaryTree()?{
??}??//?end?default?constructor
??public?BinaryTree(object?rootItem)?{
????super(rootItem);
??}??//?end?constructor
??public?BinaryTree(object?rootItem?
????????????????????BinaryTree?leftTree?
????????????????????BinaryTree?rightTree)?{
????root?=?new?TreeNode(rootItem?null?null);
????attachLeftSubtree(leftTree);
????attachRightSubtree(rightTree);
??}??//?end?constructor
??public?void?setRootItem(object?newItem)?{
????if?(root?!=?null)?{
??????root.setItem(newItem);
????}
????else?{
??????root?=?new?TreeNode(newItem?null?null);
????}??//?end?if
??}??//?end?setRootItem
??public?void?attachLeft(object?newItem)?{
????if?(!isEmpty()?&&?root.getLeft()?==?null)?{
??????//?assertion:?nonempty?tree;?no?left?child
??????root.setLeft(new?TreeNode(newItem?null?null));
????}??//?end?if
??}??//?end?attachLeft
??public?void?attachRight(object?newItem)?{
????if?(!isEmpty()?&&?root.getRight()?==?null)?{
??????//?assertion:?nonempty?tree;?no?right?child
??????root.setRight(new?TreeNode(newItem?null?null));
????}??//?end?if
??}??//?end?attachRight
??public?void?attachLeftSubtree(BinaryTree?leftTree)?
????????????????????????????????throws?TreeException?{
????if?(isEmpty())?{
??????throw?new?TreeException(“TreeException:??Empty?tree“);
????}
????else?if?(root.getLeft()?!=?null)?{
??????//?a?left?subtree?already?exists;?it?should?have?been?
??????//?deleted?first
??????throw?new?TreeException(“TreeException:?“?+?
???????????????????????????“Cannot?overwrite?left?subtree“);
????}
????else?{
??????//?assertion:?nonempty?tree;?no?left?child
??????root.setLeft(leftTree.root);
??????//?don‘t?want?to?leave?multiple?entry?points?into?
??????//?our?tree
??????leftTree.makeEmpty();?
????}??//?end?if
??}??//?end?attachLeftSubtree
??public?void?attachRightSubtree(BinaryTree?rightTree)??
?????????????????????????????????throws?TreeException?{
????if?(isEmpty())?{
??????throw?new?TreeException(“TreeException:??Empty?tree“);
????}
????else?if?(root.getRight()?!=?null)?{
??????//?a?right?subtree?already?exists;?it?should?have?been?
??????//?deleted?first
??????throw?new?TreeException(“TreeException:?“?+?
??????????????????????????“Cannot?overwrite?right?subtree“);
????}
????else?{
??????//?assertion:?nonempty?tree;?no?right?child
??????root.setRight(rightTree.root);
??????//?don‘t?want?to?leave?multiple?entry?points?into?
??????//?our?tree
??????rightTree.makeEmpty();?
????}??//?end?if
??}??//?end?attachRightSubtree
??
??protected?BinaryTree(TreeNode?rootNode)?{
????root?=?rootNode;
??}??//?end?protected?constructor
??public?BinaryTree?detachLeftSubtree()??
?????????????????????????throws?TreeException?{
????if?(isEmpty())?{
??????throw?new?TreeException(“TreeException:??Empty?tree“);
????}
????else?{
??????//?create?a?new?binary?tree?that?has?root‘s?left?
??????//?node?as?its?root
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????108??2017-07-10?12:01??-f
?????文件?????????301??2017-06-30?14:59??.classpath
?????文件?????????378??2017-06-30?14:59??.project
?????目錄???????????0??2017-06-30?14:59??.settings\
?????文件?????????598??2017-06-30?14:59??.settings\org.eclipse.jdt.core.prefs
?????文件??????????30??2017-07-05?20:11??a.freq
?????文件??????????12??2017-07-10?11:59??a.txt
?????文件???????????5??2017-07-09?13:42??a.txz
?????文件??????????78??2017-06-30?15:18??b.txt
?????目錄???????????0??2017-07-04?19:43??bin\
?????目錄???????????0??2017-07-08?11:01??bin\huffman\
?????文件????????2474??2017-07-04?19:43??bin\huffman\BinaryTree.class
?????文件????????1146??2017-07-04?19:43??bin\huffman\BinaryTreeBasis.class
?????文件?????????463??2017-07-04?19:43??bin\huffman\BitReader$NoBitsLeftToReturn.class
?????文件????????2146??2017-07-04?19:43??bin\huffman\BitReader.class
?????文件?????????502??2017-07-04?19:43??bin\huffman\BitWriter$BitWriterClosedAlreadyException.class
?????文件?????????466??2017-07-04?19:43??bin\huffman\BitWriter$InvalidBitException.class
?????文件????????2580??2017-07-04?19:43??bin\huffman\BitWriter.class
?????文件????????1062??2017-07-07?10:15??bin\huffman\CharFreq.class
?????文件????????4298??2017-07-10?11:54??bin\huffman\English_wrod.class
?????文件????????1219??2017-07-10?11:35??bin\huffman\Line.class
?????文件?????????353??2017-07-10?11:35??bin\huffman\Point.class
?????文件????????3757??2017-07-10?11:53??bin\huffman\prim.class
?????文件????????2868??2017-07-04?19:43??bin\huffman\Prim_01.class
?????文件????????3479??2017-07-10?11:15??bin\huffman\rectangle.class
?????文件????????2746??2017-07-10?11:35??bin\huffman\six.class
?????文件?????????992??2017-07-09?13:57??bin\huffman\TextZip$1.class
?????文件????????9550??2017-07-09?13:57??bin\huffman\TextZip.class
?????文件?????????348??2017-07-04?19:43??bin\huffman\TreeException.class
?????文件????????1540??2017-07-07?11:10??bin\huffman\TreeNode.class
?????文件???????????2??2017-07-10?11:53??Englishword.txt
............此處省略22個文件信息
評論
共有 條評論