Composite Pattern File System

2024-02-12 07:36
文章标签 composite system file pattern

本文主要是介绍Composite Pattern File System,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


AP(IT), Assessed Exercise 1
Jan 2024
Description
• Title: Composite Pattern File System
• Deadline: 4:30pm on February 8th 2024
• Contribution to final course mark: 25%
• Solo or Group: Solo work
Specifcation
You are to build a simplified file management system (only the meta-data) using the composite design pattern.
Within your system, you can store files and directories. Directories can include other directories and/or files. All
files and directories are within one top directory. The file system needs to be able to do the following:
• Add a file/directory to a given directory, using method void add(Component).
• Remove a file/directory from a given directory’s direct children, using method void remove(Component).
• Display a directory and all of its contents: name and size of each of its contents, whether file or directory.
• Get the size of a directory as the total size of the files within it.
• Search for a directory containing a file with a certain name. If more than one is found, only the first directory
is to be returned. File name is to be matched exactly and is case-sensitive. You can only search for file names
and not directory names.
You are required to use the following interface:
public interface Component {
public String getName();
public int getSize();
public int getCount();
public String display(String prefix);
public Component search(String name);
}
Example:
root: (count=5, size=886)
Settings (10)
music: (count=1, size=120)
ringtone (120)
pictures: (count=3, size=756)
personal: (count=2, size=335)
family-holiday (201)
portrait (134)
misc: (count=1, size=421)
wallpaper (421)
In the above example, there are 5 directories (root, music, pictures, personal and misc) and various files. Please
carefully note the format of the output including spacing and punctuation: the filesize in brackets next to each file,
the directory summary in count of files and total size, and that directory contents are indented with the prefix
(e.g. “\t”). Note that directories do not count towards the count or size; only files do.
Using the previous example, the following search parameters and their results are given:
1
• search("Settings") -> return: reference to the root directory
• search("portrait") -> return: reference to the personal directory
• search("new-photo") -> return: null reference
• search("settings") -> return: null reference
Tasks
Note that your code will be automatically marked so you need to carefully follow the instructions below.
• Start by understanding the given interface as you will need to implement it.
• Sketch out the two concrete classes that you will need to build.
• Create the components. These should be named exactly as follows: File and Directory (case-sensitive).
Remember to ensure that directories should be able to include other directories.
• Create a driver class: i.e. another class with a main method to test your system. This class will not be marked.
We provide an example of this for your own testing purposes, but different drivers with unseen input will be
used for marking. They will use similar method calls, so make sure the provided driver without editing runs
with your code. If the provided driver class fails, this means that you will be marked down so make sure
you know what’s wrong.
• Make sure that the output from your display method matches the specification above and similar to the
given example. Otherwise, the automated marker might not identify your output as correct. The marker
will identify changes in whitespace, but will deduct marks accordingly. This is the part where most
students drop marks, so please make sure you match the expected format: punctuation and
spaces (including line breaks).
• Add all your classes to a package called file1234567, where 1234567 is your student ID, ignoring the letter
at the end. If you include the letter, you will be deducted 10%.
Note that you are only allowed to import from java.util. Other imports will penalised by 30% of the total marks.
To be clear, you DO NOT need to import from java.io or any other namespace.
Submission Steps
Please follow these steps exactly or YOU WILL BE MARKED DOWN.
• We expect from you 3 files as described next (note that Java class names are case-sensitive): File.java,
Directory.java, and the given interface unedited except for adding your package name. Any other change
will be penalised. Do not submit your test driver class.
• Place your Java source files (i.e., .java NOT compiled .class) in a folder called the name of your package.
If you submit .class files, you will receive no marks.
• Any file structure different from the one described above (e.g. /bin /src . . . ) will NOT be accepted.
• For example, if your GUID is 1234567, then your folder will be of the same name, as illustrated below.
• Name the components as “File” and “Directory” exactly. Make sure that components are named starting with
a capital letter.
• Compress the whole folder into a ZIP file of the same name (i.e. file1234567.zip). No letters, numbers
or any other symbols should follow the GUID in the filename (penalty 30%). RAR, 7-zip or
any other format will be marked down by 30%.
• If the file is called anything else (such as “CW1-file1234567.zip” or “file1234567(3).zip”) you will be deducted
marks
• Submit your ZIP file through Moodle.
2
Marking Scheme
Your submission will be marked on a 100 point scale, broken down as indicated below. Note that there is substantial
emphasis on working submissions, as reflected by the large fraction of the points reserved for this aspect. It is to
your advantage to ensure that whatever you submit compiles and runs correctly.
• 25: Compilation
– 5: Submitted files do not compile but due to a simple error
– 10: Submitted files compile successfully on their own
– 10: Submitted files compile successfully with unseen test drivers (i.e. interface and public methods match
the specification)
• 40: Functionality (using unseen input)
– 10: Add files/directories
– 10: Remove files/directories
– 10: Correct display of file system
– 10: Search for directory containing a filename
• 15: Definitions (use of given interface)
– 10: Implementation of interface
– 5: Encapsulation
• 20: Design pattern
– 20: Designing the appropriate concrete components
Multiple penalties for not following the specification laid here will be accumulated   WX:codehelp

这篇关于Composite Pattern File System的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/702037

相关文章

提示:Decompiled.class file,bytecode version如何解决

《提示:Decompiled.classfile,bytecodeversion如何解决》在处理Decompiled.classfile和bytecodeversion问题时,通过修改Maven配... 目录问题原因总结问题1、提示:Decompiled .class file,China编程 bytecode

Partical System

创建"粒子系统物体"(点击菜单GameObject -> Create Other -> Particle System) 添加"粒子系统组件"(点击Component -> Effects  ->Particle System) 粒子系统检视面板  点击粒子系统检视面板的右上角的"+"来增加新的模块。(Show All Modules:显示全部) 初始化模块: •

小技巧绕过Sina Visitor System(新浪访客系统)

0x00 前言 一直以来,爬虫与反爬虫技术都时刻进行着博弈,而新浪微博作为一个数据大户更是在反爬虫上不遗余力。常规手段如验证码、封IP等等相信很多人都见识过…… 当然确实有需要的话可以通过新浪开放平台提供的API进行数据采集,但是普通开发者的权限比较低,限制也比较多。所以如果只是做一些简单的功能还是爬虫比较方便~ 应该是今年的早些时候,新浪引入了一个Sina Visitor Syst

Open a folder or workspace... (File -> Open Folder)

问题:vscode Open with Live Server 时 显示Open a folder or workspace... (File -> Open Folder)报错 解决:不可以单独打开文件1.html ; 需要在文件夹里打开 像这样

android java.io.IOException: open failed: ENOENT (No such file or directory)-api23+权限受权

问题描述 在安卓上,清单明明已经受权了读写文件权限,但偏偏就是创建不了目录和文件 调用mkdirs()总是返回false. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_E

System.getProperties().

Java.version Java 运行时环境版本 java.vendor Java 运行时环境供应商 java.vendor.url Java 供应商的 URL java.home Java 安装目录 java.vm.specification.version Java 虚拟机规范版本 java.vm.specification.vendor

12C 新特性,MOVE DATAFILE 在线移动 包括system, 附带改名 NID ,cdb_data_files视图坏了

ALTER DATABASE MOVE DATAFILE  可以改名 可以move file,全部一个命令。 resue 可以重用,keep好像不生效!!! system照移动不误-------- SQL> select file_name, status, online_status from dba_data_files where tablespace_name='SYSTEM'

bash: arm-linux-gcc: No such file or directory

ubuntu出故障重装了系统,一直用着的gcc使用不了,提示bash: arm-linux-gcc: No such file or directorywhich找到的命令所在的目录 在google上翻了一阵发现此类问题的帖子不多,后来在Freescale的的LTIB环境配置文档中发现有这么一段:     # Packages required for 64-bit Ubuntu

编译linux内核出现 arm-eabi-gcc: error: : No such file or directory

external/e2fsprogs/lib/ext2fs/tdb.c:673:29: warning: comparison between : In function 'max2165_set_params': -。。。。。。。。。。。。。。。。。。 。。。。。。。。。。。。。 。。。。。。。。 host asm: libdvm <= dalvik/vm/mterp/out/Inte

file-max与ulimit的关系与差别

http://zhangxugg-163-com.iteye.com/blog/1108402 http://ilikedo.iteye.com/blog/1554822