#!/bin/bash

ROOT='src/main/java'

JAVA_FILE="ua/nure/jfn/task1/Part1.java"
CLASS_FILE="ua/nure/jfn/task1/Part1.class"

CLASS="ua.nure.jfn.task1.Part1"

if [ ! -r "$ROOT/$JAVA_FILE"  ]; then
    echo "File '$ROOT/$JAVA_FILE' is not found or it is not readable." 1>&2
    exit 1
fi

javac "$ROOT/$JAVA_FILE"

if [ ! -r "$ROOT/$CLASS_FILE"  ]; then
    echo "Can't find '$ROOT/$CLASS_FILE' after compilation." 1>&2
    exit 2
fi

java -cp "$ROOT" "$CLASS"
