CS209 – Assignment2 (Solution)

$ 24.99
Category:

Description

Description
Please write a program named “FilesManager” that can manage files. The program will read two arguments(args[0] and args[1]) from command line.
Input: args [0]: file name or directory name args [1]: Task no.

Output: depends the Task no.
You are asked to do the following tasks:

Task no.1: recursively find out how many files the args[0] contains and output the files count.

Task no.2: calculate how much space the args[0] occupies and output the total size(unit: k).

Task no.3: find out all files which size are bigger than 1000,000 bytes and output their file name.(One line one file name.)

Task no.4: categorize files by extension, statistic the files count according different extension.(One line one extension information. Format: extension+“, ”+count. if a file has no extension, just consider its extension as “”.)

Just use System.out.println() or printf to output your result.

Here is a sample folder named Files:

If run the command:
java FilesManager Files 1

The output should be like this:
32239

If run the command:
java FilesManager Files 2
The output should be like this:
2691862k

If run the command:
java FilesManager Files 3
The output should be like this:
Files/PPTMaterial/Y1901 精品实用矢量素材.rar
Files/PPTMaterial/【55】3D小人集/3D小人图片素材/白板34.jpg
Files/PPTMaterial/【55】3D小人集/3D小人图片素材/白板35.jpg
Files/PPTMaterial/【55】3D小人集/3D小人图片素材/白板36.jpg
Files/PPTMaterial/【55】3D小人集/3D小人图片素材/坐在问号足球上的3D小人高清图片.jpg
Files/PPTMaterial/【55】3D小人集/3D小人图片素材/抱着小孩的3D小人高清图片-2.jpg
Files/PPTMaterial/【55】3D小人集/3D小人图片素材/抱着红心的3D小人高清图片.jpg
Files/PPTMaterial/【55】3D小人集/史上最全3d小人/3D小人—医疗系列.ppt
Files/PPTMaterial/【55】3D小人集/史上最全3d小人/3D小人-绿色系列.ppt
Files/PPTMaterial/【55】3D小人集/史上最全3d小人/3D小人-目标类-问号类系列.ppt
Files/PPTMaterial/【55】3D小人集/史上最全3d小人/3D小人—运动系列.pptx
Files/PPTMaterial/【55】3D小人集/史上最全3d小人/3D小人375张.ppt
Files/PPTMaterial/【55】3D小人集/彩底3D小人/彩色立体小人 (89).jpg
Files/PPTMaterial/【55】3D小人集/彩底3D小人/彩色立体小人 (48).jpg
Files/PPTMaterial/【69】精美实用PNG图标库/感叹号透明矢量PNG素材29个/感叹号 (1).jpg
Files/PPTMaterial/【69】精美实用PNG图标库/PNG图标/filetype-09.psd
Files/PPTMaterial/【69】精美实用PNG图标库/《2》高品质PNG图标新增/shutterstock_57047737.jpg
Files/PPTMaterial/Y1901 PPT常用必备素材合集.rar
Files/PPTMaterial/Y1901 2012第1季新增PNG图库-12000枚.rar
Files/PPTMaterial/Y1901 3D小人集.rar
Files/PPTMaterial/Y1901 精美实用PNG图标库.rar
Files/PPTMaterial/Y1901 素材源文件.rar
Files/images/1901554697450_.pic_hd.jpg
Files/images/1881554697436_.pic_hd.jpg
Files/images/2021554697547_.pic_hd.jpg
Files/images/1911554697457_.pic_hd.jpg
Files/images/1931554697475_.pic_hd.jpg
Files/images/1971554697504_.pic_hd.jpg
Files/images/2001554697530_.pic_hd.jpg
Files/images/1871554697429_.pic_hd.jpg
Files/images/1861554697421_.pic_hd.jpg
Files/images/1951554697489_.pic_hd.jpg
Files/images/1891554697443_.pic_hd.jpg
Files/images/1991554697522_.pic_hd.jpg
Files/images/1961554697497_.pic_hd.jpg
Files/images/1981554697512_.pic_hd.jpg
Files/images/2011554697537_.pic_hd.jpg
Files/images/1941554697482_.pic_hd.jpg

If run the command:
java FilesManager Files 4
The output should be like this:
,5
.html,1
.gif,9
.rar,6
.psd,1
.JPG,47
.jpg,1110
.PNG,131
.png,30895
.pptx,1
.ppt,10
.ico,16
.txt,2 .DS_Store,5

VERY IMPORTANT (FOR THIS LAB AND THE NEXT ONES!)
We try in this course to have assignment submissions graded by scripts whenever possible. Those scripts use techniques frequently used in professional software development: they run a series of tests and check whether the program passes or fails each test. For every assignment, we’ll try to crash your program or make it misbehave. Every failed test will mean points off. The assignment description specifies which tests will be run, so that you can check your program thoroughly before submitting it.
It’s very important:
1. That you respect what is specified in the assignment, naming, input and output (no additional message, just the required result), otherwise it will be understood as a wrong result by the script.
2. That you check that your program behaves well – no Java stack dump – for all the test cases.

Rules:
1. Please submit “.java” file. (upload it to Sakai)
2. The name of the “.java” file should be FilesManager.java
3. No Chinese characters include.
4. No package include.
5. The arguments and the output must be followed the description of each questions.
6. Your program compiles correctly (javac)
7. The result is obtained in a reasonable time.
8. Your program isn’t the same as someone else’s
DO NOT COPY!! We will check carefully!!

Reviews

There are no reviews yet.

Be the first to review “CS209 – Assignment2 (Solution)”

Your email address will not be published. Required fields are marked *