Giter Club home page Giter Club logo

ip's Introduction

Duke project template

This is a project template for a greenfield Java project. It's named after the Java mascot Duke. Given below are instructions on how to use it.

Setting up in Intellij

Prerequisites: JDK 11, update Intellij to the most recent version.

  1. Open Intellij (if you are not in the welcome screen, click File > Close Project to close the existing project first)
  2. Open the project into Intellij as follows:
    1. Click Open.
    2. Select the project directory, and click OK.
    3. If there are any further prompts, accept the defaults.
  3. Configure the project to use JDK 11 (not other versions) as explained in here.
    In the same dialog, set the Project language level field to the SDK default option.
  4. After that, locate the src/main/java/Duke.java file, right-click it, and choose Run Duke.main() (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output:
    Hello from
     ____        _        
    |  _ \ _   _| | _____ 
    | | | | | | | |/ / _ \
    | |_| | |_| |   <  __/
    |____/ \__,_|_|\_\___|
    

ip's People

Contributors

rycs2812 avatar j-lum avatar damithc avatar jiachen247 avatar

ip's Issues

Sharing iP code quality feedback [for @rycs2812] - Round 2

@rycs2812 We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).

IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.

Aspect: Tab Usage

No easy-to-detect issues ๐Ÿ‘

Aspect: Naming boolean variables/methods

No easy-to-detect issues ๐Ÿ‘

Aspect: Brace Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Package Name Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Class Name Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Dead Code

No easy-to-detect issues ๐Ÿ‘

Aspect: Method Length

Example from src/main/java/duke/Command.java lines 34-86:

    public String run(String args, Duke duke) {
        String errorMessage = getUsageError(args, duke);
        if (!errorMessage.isEmpty()) {
            // If the command is used incorrectly
            return errorMessage;
        }

        switch(name) {
        case "delete":
            int index = Integer.parseInt(args) - 1;
            return duke.deleteTask(index);

        case "find":
            if (args.charAt(0) == '"' && args.charAt(args.length() - 1) == '"') {
                args = args.substring(1, args.length() - 1);
            }
            return duke.findTask(args);

        case "list":
            return duke.listTasks();

        case "deadline":
            String[] temp = args.split(" /by ", 2);
            String[] recurring = temp[1].split(" /every ", 2);
            int period = getPeriod(temp[1]);
            Task t = new Deadline(temp[0], LocalDate.parse(recurring[0].trim(),
                    DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)), period);;
            return duke.addTask(t);

        case "event":
            temp = args.split(" /at ", 2);
            recurring = temp[1].split(" /every ", 2);
            period = getPeriod(temp[1]);
            t = new Event(temp[0], LocalDate.parse(recurring[0].trim(),
                    DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)), period);
            return duke.addTask(t);

        case "todo":
            t = new ToDo(args);
            return duke.addTask(t);

        case "mark":
            // Fallthrough

        case "unmark":
            index = Integer.parseInt(args) - 1;
            boolean b = name.equals("mark");
            return duke.markTask(index, b);

        default:
            return "";
        }
    }

Example from src/main/java/duke/Command.java lines 106-222:

    private String getUsageError(String args, Duke duke) {
        TaskList taskList = duke.getTaskList();
        String usage = getCorrectUsage();
        String error = "ERROR: \n\n";
        assert taskList != null : "Task list is null";

        switch(name) {
        case "delete":
            if (args.isEmpty()) {
                return error + "Please specify a task number.\n\n" + usage;
            }
            try {
                int index = Integer.parseInt(args);
                int count = taskList.getCount();
                if (index <= 0 || index > taskList.getCount()) {
                    return error + "Please specify a valid task number. There are "
                            + count + " tasks in the list\n\n" + usage;
                }
            } catch (NumberFormatException e) {
                return error + "Please specify a task number.\n\n" + usage;
            }

            return "";

        case "find":
            if (args.isBlank()) {
                return error + "Please specify at least one keyword.\n\n" + usage;
            } else if (args.charAt(0) != '"' || args.charAt(args.length() - 1) != '"') {
                if (args.split(" ").length > 1) {
                    return error + "'find' only expects 1 argument.\n\n If there are multiple "
                            + "keywords, please enclose them in quotation marks (\"\").";
                }
            } else {
                if (args.length() == 2 || args.substring(1, args.length() - 1).isBlank()) {
                    return error + "Please specify at least one keyword.\n\n" + usage;
                }
            }
            return "";

        case "list":
            if (!args.isEmpty()) {
                return error + "'list' expects no arguments.";
            }
            return "";

        case "deadline":
            String[] temp = args.split(" /by ", 2);
            if (temp.length < 2) {
                return error + "Please specify a task and deadline.\n\n" + usage;
            } else {
                String[] recurring = temp[1].split(" /every ", 2);
                int period = getPeriod(temp[1]);
                if (period < 0) {
                    return error + "Please specify a valid period for recurring tasks.\n\n" + usage;
                } else if (period == 0) {
                    if (!isValidDate(temp[1])) {
                        return error + "Please specify the due date in the right format.\n\n" + usage;
                    }
                }
                if (!isValidDate(recurring[0])) {
                    return error + "Please specify the due date in the right format.\n\n" + usage;
                }
            }
            return "";

        case "event":
            temp = args.split(" /at ", 2);
            if (temp.length < 2) {
                return error + "Please specify an event and date.\n\n" + usage;
            } else {
                String[] recurring = temp[1].split(" /every ", 2);
                int period = getPeriod(temp[1]);
                if (period < 0) {
                    return error + "Please specify a valid period for recurring tasks.\n\n" + usage;
                } else if (period == 0) {
                    if (!isValidDate(temp[1])) {
                        return error + "Please specify the event date in the right format.\n\n" + usage;
                    }
                }
                if (!isValidDate(recurring[0])) {
                    return error + "Please specify the due date in the right format.\n\n" + usage;
                }
            }

            return "";

        case "todo":
            if (args.isEmpty()) {
                return error + "Please specify a task.\n\n" + usage;
            }
            return "";

        case "mark":
            // Fallthrough

        case "unmark":
            if (args.isEmpty()) {
                return error + "Please specify a task number\n\n" + usage;
            } else {
                try {
                    int index = Integer.parseInt(args) - 1;
                    if (index < 0 || index >= taskList.getCount()) {
                        return error + "Please specify a valid task number.\n"
                                + "There are " + taskList.getCount()
                                + " task(s) in the list.\n\n" + usage;
                    }
                } catch (NumberFormatException e) {
                    return error + "Please specify a task number.\n"
                            + "\"" + args + "\"" + " is not a task number\n\n" + usage;
                }
            }
            return "";

        default:
            return "";
        }
    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.

Aspect: Class size

No easy-to-detect issues ๐Ÿ‘

Aspect: Header Comments

No easy-to-detect issues ๐Ÿ‘

Aspect: Recent Git Commit Message (Subject Only)

No easy-to-detect issues ๐Ÿ‘

Aspect: Binary files in repo

No easy-to-detect issues ๐Ÿ‘

โ— You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality issues.

โ„น๏ธ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact [email protected] if you want to follow up on this post.

Sharing iP code quality feedback [for @rycs2812]

@rycs2812 We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.

IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.

Aspect: Tab Usage

No easy-to-detect issues ๐Ÿ‘

Aspect: Naming boolean variables/methods

Example from src/main/java/duke/Task.java lines 10-10:

    private boolean marked;

Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)

Aspect: Brace Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Package Name Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Class Name Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Dead Code

No easy-to-detect issues ๐Ÿ‘

Aspect: Method Length

Example from src/main/java/duke/Command.java lines 35-127:

    public void run(String args, Duke duke) {
        UI ui = duke.getUI();
        TaskList taskList = duke.getTaskList();
        Storage storage = duke.getStorage();

        if (!isCorrectUsage(args, duke)) {
            return;
        }
        switch(name) {
        case "delete":
            int index = Integer.parseInt(args) - 1;
            Task t = taskList.deleteTask(index);
            ui.printTaskDeleted(t, taskList.getCount());
            try {
                storage.rewriteFile(taskList.getTasks());
            } catch (IOException e) {
                ui.printError("Unable to write to file.");
            }
            break;

        case "find":
            if (args.charAt(0) == '"' && args.charAt(args.length() - 1) == '"') {
                args = args.substring(1, args.length() - 1);
            }
            ArrayList<Task> matchingTasks = taskList.getMatchingTasks(args);
            if (matchingTasks.isEmpty()) {
                ui.print("No results found for keyword '" + args + "'");
            } else {
                ui.printTasks(matchingTasks, "Here are the matching tasks in your list:");
            }
            break;

        case "list":
            ui.printTasks(duke.getTaskList().getTasks(), "Here are the tasks in your list:");
            break;

        case "deadline":
            String[] temp = args.split(" /by ", 2);
            t = new Deadline(temp[0], LocalDate.parse(temp[1],
                    DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)));
            taskList.addTask(t);
            ui.printTaskAdded(t, taskList.getCount());
            try {
                storage.appendTaskToFile(t);
            } catch (IOException e) {
                ui.printError("Unable to write to file.");
            }
            break;

        case "event":
            temp = args.split(" /at ", 2);
            t = new Event(temp[0], LocalDate.parse(temp[1],
                    DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)));
            taskList.addTask(t);
            ui.printTaskAdded(t, taskList.getCount());
            try {
                storage.appendTaskToFile(t);
            } catch (IOException e) {
                ui.printError("Unable to write to file.");
            }
            break;

        case "todo":
            t = new ToDo(args);
            taskList.addTask(t);
            ui.printTaskAdded(t, taskList.getCount());
            try {
                storage.appendTaskToFile(t);
            } catch (IOException e) {
                ui.printError("Unable to write to file.");
            }
            break;

        case "mark":
            // Fallthrough

        case "unmark":
            index = Integer.parseInt(args) - 1;
            t = taskList.getTasks().get(index);
            boolean b = name.equals("mark");
            taskList.markTask(t, b);
            ui.printTaskMarked(t, b);
            try {
                storage.rewriteFile(taskList.getTasks());
            } catch (IOException e) {
                ui.printError("Unable to write to file.");
            }
            break;

        default:
            break;
        }
    }

Example from src/main/java/duke/Command.java lines 138-231:

    private boolean isCorrectUsage(String args, Duke duke) {
        UI ui = duke.getUI();
        TaskList taskList = duke.getTaskList();
        String usage = getCorrectUsage();
        switch(name) {
        case "delete":
            if (args.isEmpty()) {
                ui.printError("Please specify a task number.\n\n" + usage);
                return false;
            }
            return true;

        case "find":
            if (args.isBlank()) {
                ui.printError("Please specify at least one keyword.\n\n" + usage);
                return false;
            } else if (args.charAt(0) != '"' || args.charAt(args.length() - 1) != '"') {
                if (args.split(" ").length > 1) {
                    ui.printError("'find' only expects 1 argument.\n\n If there are multiple "
                            + "keywords, please enclose them in quotation marks (\"\").");
                    return false;
                }
            } else {
                if (args.length() == 2 || args.substring(1, args.length() - 1).isBlank()) {
                    ui.printError("Please specify at least one keyword.\n\n" + usage);
                    return false;
                }
            }
            return true;

        case "list":
            if (!args.isEmpty()) {
                ui.printError("'list' expects no arguments.");
                return false;
            }
            return true;

        case "deadline":
            String[] temp = args.split(" /by ", 2);
            if (temp.length < 2) {
                ui.printError("Please specify a task and deadline.\n\n" + usage);
                return false;
            } else if (!isValidDate(temp[1])) {
                ui.printError("Please specify the due date in the right format.\n\n" + usage);
                return false;
            }
            return true;

        case "event":
            temp = args.split(" /at ", 2);
            if (temp.length < 2) {
                ui.printError("Please specify an event and date.\n\n" + usage);
                return false;
            } else if (!isValidDate(temp[1])) {
                ui.printError("Please specify the event date in the right format.\n\n" + usage);
                return false;
            }
            return true;

        case "todo":
            if (args.isEmpty()) {
                ui.printError("Please specify a task.\n\n" + usage);
                return false;
            }
            return true;

        case "mark":
            // Fallthrough

        case "unmark":
            if (args.isEmpty()) {
                ui.printError("Please specify a task number\n\n" + usage);
                return false;
            } else {
                try {
                    int index = Integer.parseInt(args) - 1;
                    if (index < 0 || index >= taskList.getCount()) {
                        ui.printError("Please specify a valid task number.\n"
                                + "There are " + taskList.getCount()
                                + " task(s) in the list.\n\n" + usage);
                        return false;
                    }
                    return true;
                } catch (NumberFormatException e) {
                    ui.printError("Please specify a task number.\n\n"
                            + "\"" + args + "\"" + " is not an item number\n" + usage);
                    return false;
                }
            }

        default:
            return false;
        }
    }

Example from src/main/java/duke/Storage.java lines 27-79:

    public ArrayList<Task> load() throws FileNotFoundException {
        File f = new File(filePath);
        f.getParentFile().mkdirs();
        try {
            if (!f.exists()) {
                f.createNewFile();
            }
        } catch (IOException e) {
            System.out.println("Unable to read file.");
        }

        ArrayList<Task> tasks = new ArrayList<>();
        Scanner s = new Scanner(f);
        while (s.hasNext()) {
            String nextTask = s.nextLine();
            String[] temp = nextTask.split("\\[");
            Character taskType = temp[1].charAt(0);
            Boolean marked = temp[2].charAt(0) == 'X';
            String dateTemp = temp[temp.length - 1];
            dateTemp = dateTemp.substring(0, dateTemp.length() - 1);
            LocalDate date = LocalDate.now();
            if (!dateTemp.isEmpty()) {
                date = LocalDate.parse(dateTemp);
            }
            String task = "";
            for (int i = 3; i < temp.length - 1; ++i) {
                if (i < temp.length - 2) {
                    task += temp[i];
                    task += "[";
                } else {
                    task += temp[i].substring(0, temp[i].length() - 1);
                }
            }

            switch(taskType) {
            case 'T':
                addTask(tasks, new ToDo(task), marked);
                break;

            case 'D':
                addTask(tasks, new Deadline(task, date), marked);
                break;

            case 'E':
                addTask(tasks, new Event(task, date), marked);
                break;

            default:
                break;
            }
        }
        return tasks;
    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.

Aspect: Class size

No easy-to-detect issues ๐Ÿ‘

Aspect: Header Comments

No easy-to-detect issues ๐Ÿ‘

Aspect: Recent Git Commit Message (Subject Only)

No easy-to-detect issues ๐Ÿ‘

Aspect: Binary files in repo

No easy-to-detect issues ๐Ÿ‘

โ„น๏ธ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact [email protected] if you want to follow up on this post.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.