Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

GENERAL INSTRUCTIONS: -------------------- Your task is to define a class with o

ID: 3562848 • Letter: G

Question

GENERAL INSTRUCTIONS:

--------------------
Your task is to define a class with one method, described below.

Your class must be defined in a package 'CD' placed in the 'SC' folder.

Your class must be named 'HW'.

Your method must be non-static and named 'count'. Its return type must be
'HashMap<String,Integer>' and its parameter must be of type 'String'. Your
class must have a no-argument constructor.

The functionality of your definitions will be verified by JUnit tests.


HOMEWORK-SPECIFIC INSTRUCTIONS:
------------------------------

A description of the required (public) method:

   /**************************************************************************
   * @param a String denoting the inputPath the path on the local filesystem
   * to the input file
   * @returns a HashMap<String,Integer> containing the word->count mappings
   *
   * This method must read the contents of a file (identified by inputFilePath),
   * one char at a time, segment the input into words, and keep track of word
   * counts in a java.util.HashMap<String,Integer>.
   *
   * A word is defined as a contiguous sequence of characters that does not
   * contain word separator characters, where word separator characters are:
   * ' ' (space), ' ' (tab), ' ' (newline), ',' (comma) and '.' (period).
*
* Think carefully about this definition, and how it applies to an initial
* character sequence not preceded by a word separator, and also a final
* character sequence not followed by a word separator.
   *   
   * You must use only CharacterFromFileReader to read characters from the input
   * file. Use it as an Iterator<Character>, keeping in mind the autoboxing &
   * unboxing feature of the Java language.
   *
   * In order to keep your code readable, break your code into several methods.
   * Define meaningful private helper methods that you call from the required
   * public method.

Explanation / Answer

import os print("Path at terminal when executing this file") print(os.getcwd() + " ") print("This file path, relative to os.getcwd()") print(__file__ + " ") print("This file full path (following symlinks)") full_path = os.path.realpath(__file__) print(full_path + " ") print("This file directory and name") path, file = os.path.split(full_path) print(path + ' --> ' + file + " ") print("This file directory only") print(os.path.dirname(full_path))