import java.util.*;
import java.io.*;

public class Course {
    private final int MIN_NAME_LEN = 10;
    private final int MAX_NAME_LEN = 100;

    private String department;
    private String catalog_no;
    private String name;

    public Course (String department, String catalog_no, String name) 
        throws IllegalArgumentException{
            if (department_good(department) && catalog_no_good(catalog_no) &&
                 name_good(name)){
            this.department = department;
            this.catalog_no = catalog_no;
            this.name       = name;
        }   
    }

    public String toString() {
        return department + " " + catalog_no + ": " + name;
    }

    private boolean department_good(String value) throws IllegalArgumentException{
        boolean value_good = value.equals("IT");
        if (! value_good ){
            throw new IllegalArgumentException("Department must be IT");
        } else {
            return value_good;
        }
    }

    private boolean catalog_no_good(String catalog_no) throws IllegalArgumentException{
        switch (catalog_no) {
            case "114":
            case "116":
            case "117":
            case "244":
            case "246":
            case "285":
            case "341":
            case "442":
            case "443":
            case "444":
            case "485":
                return true;
            default:
                throw new IllegalArgumentException(catalog_no + " is not valid");
        }
    }

    private boolean name_good(String name){
        if (name.length() >= MIN_NAME_LEN && name.length() <= MAX_NAME_LEN) {
            return true;
        } else {
            throw new IllegalArgumentException("name must be between " + MIN_NAME_LEN +
                                                " and " + MAX_NAME_LEN + " characters long");
        }
    }

    public String department(){
        return department;
    }

    public String catalog_no(){
        return catalog_no;
    }

    public String name(){
        return name;
    }

    public String store_string(){
        String store_text = "course\n";
        store_text += department + "\n";
        store_text += catalog_no + "\n";
        store_text += name + "\n";
        return store_text;
    }
    
    public static Course add_course(Scanner console) throws FileNotFoundException{
        String department = get_field_value(console, "Department");
        String course_no  = get_field_value(console, "Catalog number");
        String name       = get_field_value(console, "Name");
        Course course     = new Course(department, course_no, name);
        return course;
    }

    private static String get_field_value(Scanner console, String field_name)
        throws FileNotFoundException {
        System.out.print(field_name + ": ");
        String field_value = console.nextLine();
        return field_value.trim();
    }

}