For this project, you will create a class called
utility methods that can be used in different applications.
This class is not intended to be a complete application by itself!
(It has no
Your class will be put into a package called
The package will then be documented using the
tool to create HTML
documentation for your package.
Finally, you will create a small stand-alone non-GUI
Java program that tests the methods of your
(Your next project will use this package, and you won't be allowed to
make any changes to
TextKit once submitted.)
Create a public Java class named “
TextKit” in a
package called “
utils” that contains the following
public static methods (at least):
Stringcontaining a line of asterisks (or stars). This method must take a single parameter only, an
intwhich says how many stars to draw. For example, the code:
lineOfStarsshould be a generally useful method that given a single number returns a
Stringof that many stars. (Such a method could easily be reused in another project someday.)
Stringa certain minimum length. (If the number contains more digits than the specified width, then no padding is added.) This method must take two
intarguments, the first is the number to format, and the second is the desired minimum
Stringlength. The resulting
Stringis returned. For example, the code:
pad, to make the field length 4.)
To facilitate such reuse, these methods must
methods of a public class called
which must be in a
(Someday you might add other text utility methods to this class
or add other classes to this package.)
Be sure to add appropriate Java doc comments throughout your code!
For full credit, your methods must check for
invalid arguments (for example, inappropriate negative numbers).
If you detect invalid arguments passed to a method, the method must
throw an appropriate
Next, create a testing application.
Your test program (containing just a
should not be in the
utils package, but rather
in the default, nameless package.
You can name the class anything you like; something like
TextKitApp is fine.
This test program should invoke each method of the
utils.TextKit class at least once, to verify
those methods work.
You can test the resulting
String object returned from each
method, against the expected value.
Or you can simply print a message that says something like
“You should see five stars here: ”, followed by the
output of the method call with (in this example) the argument
main method is sometimes referred to
as a test driver.)
A good test driver will have many test cases, to more thoroughly
check the methods.
Having failing cases (in a
try...catch block of course)
is also a good idea, but not required for this project.
Finally, you must use the
javadoc tool to create
HTML documentation for your package.
This documentation should be placed in a directory called
docs directory should not be placed
inside of the
Note, only the code in the package needs to be documented with
Java doc comments; your test driver only needs regular style comments.
For this project, no normal email submissions will be
Instead, you should submit a zip attachment via MyHCC
The zip should contain the correct files and directories:
Your testing application source, your
utils package source.
(You don't have to send any
You must send this email using MyHCC.
Use a subject of “Java TextKit Project Submission”.
Email sent to regular email addresses that contains a zip
file attachment will be discarded by the mail server, if they contain any
You can instead submit a flash disk or CD-ROM,
with your name on it,
containing your test program at the top (root) directory,
a directory called
utils containing the
TextKit class and Java source code file, and
another directory (not under
docs containing the
HTML output of the
which should be generated using all the appropriate options as
shown in class.
(Please don't have other files on this; I don't wish to hunt
around for the right ones.)
Send project questions to . Please use a subject such as “Java TextKit Project Questions” so I can tell which emails are questions about the project.
TextKit is not a complete application.
It is intended to be used in many different future applications.
This is an example of reusable (or library) code.
In this case, your methods do not read any input, nor produce any
Rather, they produce and return a result solely from the arguments passed in
from some other class, in a similar way to methods such as
Use PkgDemo as a model
to create and use packages.
See JavaDoc Demo - Greeter demo as a model
to use the
(Remember that the Java
contains information about all tools, including
You program should be easily read and well commented, including your name. Be sure to have the “doc” comments for each class and each method, in the correct locations, or they won't show up in the generated API web pages. (So, check that to make sure all your doc comments did show up.)
What is an illegal argument?
If you try to pass something other than an int to
a method expecting an
int argument, you get
a compiler error message.
That's not what is meant by an illegal argument.
That would just be a syntax error that the compiler catches for you.
What the compiler can't catch is when you pass an
int value that makes no sense.
In the case of
what should that method do if you pass a negative integer?
Or a huge integer, say over one million?
The Java compiler can't detect such illegal argument values.
(In some languages you can more precisely define argument types,
including legal ranges.
In such languages the compiler can detect the problem!)
So, you check arguments at the top of methods in reusable code modules
TextKit, and if they are illegal then the method
should throw exceptions.
A programmer is an expert problem solver.
To solve a task such as
you can make use of a design method that works in lots of cases.
The idea is to try to solve a simpler problem.
Then you can repeat that step in a loop to solve the original
This general idea of solving a problem by breaking a difficult task
into very simple tasks (baby steps)
and then repeating or combining those steps, is known as
divide and conquer.
You can apply this idea to the task of
To start with, create an empty String.
To add one star to this you can use a similar solution to adding
a number to a variable (num = num + something).
You need to take the existing string of stars, append one "*" to
the right end, and the new String object replaces the original.
Once you can add one star to a String, so you need to repeat that
step the correct number of times to produce a String with the
correct number of stars.
To make this idea efficient consider how you might use a
StringBuilder instead of a
You can apply this idea to the design of
pad as well.
Java 5 added many new features, including the ability to format numbers easily. You don't have to use this feature, but if you find it and figure out how to use it (which isn't easy) you can pad a number in a single line of code!
Ask me for help if you get stuck! (Try not to wait until the deadline!)