Lab Assignment #9 supplement: Classes
Due in lab, Thursday and Friday, April 15 and 16.
NOTE The in-lab exercise for this lab will not be
part of lab 9 grade. However, it will count as extra credit for your
assignments. We will only spend part of the lab talking about this
exercise; we will discuss lab 9 and the projects during the rest of
the lab.
In-Lab Work
A class hierarchy design
For this lab, you will design a somewhat conceptual class hierarchy
of files and directories. A file is a superclass of different types of
files. A directory is a class that has a number of files and/or directories in an
array. In the lab, you will mainly use this example to come up with an
object-oriented design that involves inheritance, overloading and
polymorphism.
The main goal of this in-lab is to come up with a design that
should satisfy some desireable properties. A proper working program is
not the main goal. You probably should draw a class hierarcy diagram
on paper before you actually try writing any code. You can put all
your classes in the same file (remember when you put multiple classes
in the same file, only one class should be public, and the rest should
be defined as just classes, like the following:
public class FileSystem {
public static void main(String[] args) {
...
}
class File {
...
}
etc.
The above file should be saved as FileSystem.java.
Your design for this in-lab exercise should have the following
properties:
- Lets assume you can only have two special type of files - a text
file, and an image file. All other files are generic file types,
for which no applications have been defined.
- Think about the relationship between text files, image files, and directories. Are they all types of files, or do they have a different type of relationship.
- All files have common properties such as name, type and
size that need to be specified when a file is created. You
should use the ccj Time class to set the modification time of
the file to the time when the file is created.
- A directory can only have a fixed maximum number of files in it
(say, 20).
- A directory can contain other directories just like it can
contain other files.
- You can open a file with an application, or you can simply open
it, in which a proper application is automatically called for known file types. For generic file types, the user is asked for what application
should be called.
- When you open a directory all contents (both files and directories) should be displayed.
- You can add a file (or another directory) to a directory.
In the lab, with the help of your AI, come up with a class design that
satisfies all the above properties. Draw the class hierarchy diagram,
and write down all the methods and data properties that these classes
should have. Then write basic skeleton structures of these
methods. Your program may not do anything useful, but you should be
able to compile it.