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

相关推荐
淡海水2 分钟前
C#与常用数据结构源码剖析-全篇导览
开发语言·数据结构·unity·面试·职场和发展·c#
wear工程师3 分钟前
Java 类初始化到底何时触发?别把加载、连接和 static 执行混在一起
java·jvm
hard_hot5 分钟前
RabbitMQ异步下单架构设计
java·rabbitmq·java-rabbitmq
问天_观心11 分钟前
python之uv库的学习
开发语言·python
郑州光合科技余经理12 分钟前
餐饮预定系统架构拆解:订单链路、权限组织与私有化源码交付
java·开发语言·前端·数据库·人工智能·系统架构·php
在世修行21 分钟前
从零打造 C# 工业视觉检测系统(十五):项目打包部署与进阶展望
开发语言·c#·视觉检测
vx-程序开发27 分钟前
django汽车租赁系统---附源码25360
java·javascript·spring boot·python·eclipse·django·php
zhougl99632 分钟前
Java实现腾讯云开发者社区列表爬虫
java·爬虫·腾讯云
智码看视界34 分钟前
Day49-AI微服务化-将大模型能力封装为标准微服务
java·微服务·ai·架构·大模型·sse流式输出·ai中台
Nebula_g34 分钟前
JavaSE基础语法:特殊类(特殊情景下的设计模式)
java·开发语言·设计模式