import java.text.ParseException; /** Hold a line from Shakespeare and some associated info * @author gtowell * created: Sep 28, 2020 */ public class Line { // The play the line is in private String play; // The speaker of the line private String speaker; //Line count within play private int lineno; //the line itself private String theLine; /** * Parse a string into the parts of a line * @param delimitedLine the string to parse * @throws ParseException if the parse fails * @throws NumberFormatException if the linenumber cannot be interpreted as a number */ public Line(String delimitedLine) throws ParseException, NumberFormatException { String[] parts = delimitedLine.split("::"); if (parts.length != 4) throw new ParseException(delimitedLine + " Does dot break up as expected", 1); play=parts[0].trim(); speaker = parts[1].trim(); lineno = Integer.parseInt(parts[2].trim()); theLine = parts[3].trim(); } public String toString() { return theLine; } public String getText() { return theLine; } }