Commit 0cce2a25 authored by jcechace's avatar jcechace
Browse files

Initial version of hw03 assignment

# Created by .ignore support plugin (
### Java template
# Mobile Tools for Java (J2ME)
# Package Files #
# virtual machine crash logs, see
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
## Directory-based project format:
# if you remove the above rule, at least ignore the following:
# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml
# Gradle:
# .idea/gradle.xml
# .idea/libraries
# Mongo Explorer plugin:
# .idea/mongoSettings.xml
## File-based project format:
## Plugin-specific files:
# IntelliJ
# mpeltonen/sbt-idea plugin
# JIRA plugin
# Crashlytics plugin (for Android Studio and IntelliJ)
### Maven template
### Eclipse template
# Eclipse Core
# External tool builders
# Locally stored "Eclipse launch configurations"
# CDT-specific
# JDT-specific (Eclipse Java Development Tools)
# Java annotation processor (APT)
# PDT-specific
# sbteclipse plugin
# TeXlipse plugin
### NetBeans template
# Vim
# VSCode
# OS X .DS_Store
image: maven:3-jdk-10
- mvn clean install -B
- shared-fi
Homework assignment no. 2, RPG Character generator
**Publication date:** 15th May
**Submission deadline:** 5th June 23:59
General information
In this assignment you will create a command line application which can be used to generate an HTML overview of a character for a very simple tabletop RPG system.
First and foremost... "What the hell is a tabletop RPG?"
It's a role playing game in which participants describe their character and act as them through speech, writings, and drawings. The entire game is usually driven by another participant (called Dungeon Master -- DM) who acts as a storyteller.
You might have encountered the most famous tabletop RPG game system [DnD (Dungeons & Dragons)]( or its czech counterpart [Dračí Doupě (DrD)](
### Game System Information
Our game system will be much simpler than those of DnD or DrD. We wont have any classes or leveling system. There will be just characters with predetermined set of skills and attributes.
Each character has some basic information such as name**name**, age, occupation.
In addition character also has a set of attributes (e.g. strength, dexterity) and set of skills (e.g. leadership, intimidation) -- each of these has a rank between 0 and 5.
As you play the game you will encounter many situations. Lets say your group captured certain street thug and needs to know what he did last night.
Since your character has the interrogation you decide to press on the thug and extract the information. The dungeon master determines that you need at least 3 success points to get the information you need.
At this point, since you character has 4 points in the interrogation skill, you roll with four 10-sided dice. If you get a result higher than 4 on at least 3 ouf them, you will succeed in interrogating the thug.
It's a very simple, yet versatile and fast-paced system.
### Application Usage and Overview
As already mentioned, the goal is to implement a command line utility which will produce a character sheet for our tabletop RPG. The program will recognize the following command line options
| Name | Default Value | restriction |Description |
| --name | - | - | Character's name |
| --age | - | positive integer |Character's age |
| --occupation | Citizen |- | Character's occupation |
| --health | - | 1-10 |Character's health |
| --sanity | - |1-10 | Character's sanity |
| --inventory | 42 | positive, x % 3 = 0 | Character's inventory size |
| --attrs | attributes.txt | - | Attribute file descriptor |
| --skills | skills.txt | - | Skills file descriptor |
| --out | character.html | - | output file name |
| --encoding | UTF-8 | - | Encoding of input files |
| --help |false | - | when present displays program help|
Parameters without default value are mandatory and the program could be called for example as follows...
java -jar rpg-gen.jar --name "Stephen Mercer" --age 32 --occupation "Investigative Journalist" --health 5 --sanity 5 --inventory=45 \
--attrs "stephen_attrs.txt" --skills "stephen_skills.txt"
An example of file descriptors can be found in ```src/test/resources```. A generic format is
AbilityOrSkill 5
AbilityOrSkill R
Each ability or sill is placed on single line defined as combination of name and level.
Level can be specified either as a number between 0 and 5 or as "R". When "R" is used as level, then the actual value is computed as a random within mentioned range.
### External Libraries
In this assignment you will encounter two useful java libraries
#### JCommander
JCommander is a small library for parsing command line arguments. The documentation and examples can be found [here](
In this homework you will learn just the basic by replicating what is already present in the skeleton of ```Application``` class.
### Thymeleaf
Thymeleaf is a very complex templating library which allows for templating of various documents from simple text, through html, to javascript files.
In this homework you will be required to fill in a small part of a template. Other than that you are encouraged to have a look at how to use this library.
The documentation can be found [here](
## Evaluation
Beside functional correctness this assignment is focused on clean implementation and your understanding of Java's collection framework.
The maximum number of points for this assignment is **11**.
- **5 points** for passing tests (attached tests do not guarantee a 100% correctness).
- **6 points** for clean implementation and creativity.
Note that all this is at your seminar teacher's discretion.
### Preconditions
To successfully implement this assignment you need to learn the following
1. Working with files (java.nio package)
2. Understand more complex code provided by 3rd party
3. Working with external libraries
### Project structure
The structure of project provided as a base for your implementation should meet the following criteria.
1. Package `````` contains classes and interfaces provided as part of the assignment.
- **Do not modify or add any classes or subpackages into this package.**
2. Package `````` should contain your implementation.
- **Anything outside this package will be ignored during evaluation.**
### Names in this document
Unless fully classified name is provided, all class names are relative to package `````` or `````` for classes implemented as part of your solution.
### Compiling the project
The project can be compiled and packaged in the same way you already know
$ mvn clean compile
The only difference is, that unlike with seminar project, this time checks for missing documentation and style violation will produce an error.
You can temporarily disable this behavior when running this command.
$ mvn clean compile
You can consult your seminar teacher to help you set the `````` property in your IDE (or just google it).
### Submitting the assignment
The procedure to submit your solution may differ based on your seminar group. However generally it should be ok to submit ```target/homework01-2020-1.0-SNAPSHOT-sources.jar``` to the homework vault.
### Step 1: Implementing Character class
Implement the ```Character``` class with the following attributes. In order to help you a bit there is already a very sparse skeleton in place.
| Name | Type | Description |
| -----|------|-------------|
| name | String | character's name |
| age | int | characters age |
| occupation | String | character's occupation |
| health | int | character's health |
| sanity | int | character's sanity |
| attributes | List<SkillOrAttribute> | character's attributes |
| skills | List<SkillOrAttribute> | character's skills |
Since the class has quite a few attributes, you should provide ```Builder``` class -- a builder implementation which will be used to construct instances of ``Character`` class.
This builder should implement ```Buildable``` interface as well as ```read.AttributeReader``` and ```read.SkillReader```;
### Step 2: Implementing the command line interface
Extend the implementation of ``Application`` class in order for it to recognise all of the command line parameters described above.
In order to validate some of the value, you will need to read section *4.1. Individual parameter validation* in JCommander's documentation.
Program usage info should be displayed when ``--help`` is specified as command line parameter.
### Character to HTML file
Running the ``main`` method of ``Application`` class should produce a HTML file with character information.
To achieve this you should use the Thymeleaf library already mentioned in this assignment.
To have easier time working with this library, you can use the class ```impl.AbstractHtmlWriter``` and prepared template located in ```src/main/resources```.
However this template is not complete and you will have to fill in few things.
Also notice that ``AbstractHtmlWriter`` is located inside the ```impl``` package, which means that you can modify it to suit your needs.
\ No newline at end of file
<?xml version="1.0"?>
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
<module name="Checker">
<!--<property name="fileExtensions" value="java, xml, properties"/>-->
<!-- Checks for whitespace -->
<!-- See -->
<module name="FileTabCharacter"/>
<module name="TreeWalker">
<!-- Checks for Javadoc comments. -->
<!-- See -->
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingPropertyJavadoc" value="true"/>
<property name="ignoreMethodNamesRegex" value="^(get|set)+[A-Z]+.*$"/>
<module name="JavadocType">
<property name="scope" value="public"/>
<module name="JavadocStyle">
<property name="scope" value="public"/>
<property name="checkFirstSentence" value="false"/>
<!-- Checks for Naming Conventions. -->
<!-- See -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<!-- Checks for imports -->
<!-- See -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<!-- Checks for Size Violations. -->
<!-- See -->
<module name="LineLength">
<property name="max" value="120"/>
<module name="MethodLength">
<property name="max" value="50"/>
<property name="countEmpty" value="false"/>
<!-- Modifier Checks -->
<!-- See -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See -->
<module name="AvoidNestedBlocks"/>
<module name="LeftCurly">
<property name="option" value="eol"/>
<module name="NeedBraces">
<property name="allowSingleLineStatement" value="false"/>
<module name="RightCurly"/>
<!-- Checks for common coding problems -->
<!-- See -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="MissingSwitchDefault"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<!-- Checks for class design -->
<!-- See -->
<module name="InterfaceIsType"/>
<module name="VisibilityModifier">
<property name="protectedAllowed" value="true"/>
<!-- Miscellaneous other checks. -->
<!-- See -->
<module name="ArrayTypeStyle"/>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi=""
<!-- Include sources into JAR -->
<!-- Executable bar -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<!-- surefire Config -->
<!-- Check code style -->
* A base interface for builder implementations
* @author Jakub Cechacek
* @param <T> type of built object
public interface Buildable<T> {
* Build an instance of {@link T}
* @return instance of {@link T}
T build();
* Representation of either Skill or Attribute
* @author Jakub Cechacek
public class SkillOrAttribute {
private String name;
private int level;
* Constructor for this class
* @param name name of the skill/attribute
* @param level level of the skill/attribute
public SkillOrAttribute(String name, int level) { = name;
this.level = level;
public String getName() {
return name;
public int getLevel() {
return level;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
* Base class capable of serialising character into HTML string
* @author Jakub Cechacek
public abstract class AbstractHtmlWriter implements CharacerSerializer<String>, CharacterFileWriter {
public static final String TEMPLATE = "/templates/character.html";
public String serialize(Character character) {
ClassLoaderTemplateResolver tr = new ClassLoaderTemplateResolver();
TemplateEngine templates = new TemplateEngine();
Context context = new Context();
context.setVariable("character", character);
return templates.process(TEMPLATE, context);
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
* Character Generator application
* @author Jakub Cechacek
public class Application {
@Parameter(names = "--help", help = true)
private boolean help = false;
@Parameter(names = {"--encoding"})
private String encoding = "UTF-8";
@Parameter(names = {"--name"}, required = true)
private String name;
@Parameter(names = {"--occupation"})
private String occupation = "Citizen";
// TODO: Fill in the missing command line parameters
* Program entry point.
* You should parse the command line arguments and produce output html file according to them.
* @param args raw command line arguments
public static void main(String[] args) {
Application app = new Application();
JCommander commander = JCommander.newBuilder().addObject(app).build();
// TODO: finish the code
// HINT: Attributes in the app object are populated with parsed command line values
* Representation of game character
* @author Jakub Cechacek
public class Character {
* Builder class fro {@link Character}
public static class Builder {
// TODO: implement the builder