Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You will be working with a Java project that has 1 class called BuildSpellbook. For your tasks, you ll be adding attributes and methods to
You will be working with a Java project that has class called BuildSpellbook. For your tasks, youll be adding attributes
and methods to existing classes given in the code bundle accompanying these specs; this is indicated by the comment
TODO. Where its given, you should use exactly the method stub provided for implementing your tasks. Dont
change the names or the parameters or exception handling. You can add more methods if you like.
There also some methods provided, in particular for reading from files. These files, with suffixes in for input files and
out for output files, will be read in such that each line is returned as a single string, and the whole file is turned into a
Vector of strings. There are separate ones for reading in input files and output files:
public Vector readSpecsFromFileString fInName throws IOException
PRE:
POST: returns lines from input file as vector of string
CODE PROVIDED
public Vector readSolnFromFileString fInName, Integer N throws IOException
PRE:
POST: returns up to N lines from input file as a vector of N strings;
only the specification lines are counted in this N not responses
CODE PROVIDED
There is also a method for comparing the output of your code with the model output file:
public Boolean compareExecWSoln Vector execd, Vector soln
PRE:
POST: Returns True if execd and soln stringmatch exactly, False otherwise
CODE PROVIDED
A Java file of sample JUnit tests, SampleTests, is also provided; it uses the sample data files provided.
package student;
import java.ioBufferedReader;
import java.ioFileReader;
import java.ioIOException;
import java.util.Vector;
public class BuildSpellbook
public final Integer MAXCOMS ; maximum number of specs
Attributes
private Vector specs;
public BuildSpellbook
Constructor
specs new Vector;
public Vector execNSpecsVector specs, Integer N
PRE: specs contains set of specifications read in by readSpecsFromFile
POST: executed minN all specifications,
returning required output, one line per string in vector
Vector result new Vector;
for int i ; i Math.minN specs.size; i
result.addExecuted: specs.geti;
return result;
public Vector execNSpecswCheckVector specs, Integer N
PRE: specs contains set of specifications read in by readSpecsFromFile
POST: executed minN all specifications, checking for cycles,
returning required output, one line per string in vector
Assuming cycle check logic is implemented
Vector result new Vector;
for int i ; i Math.minN specs.size; i
Check for cycles dummy check for illustration
if hasCyclespecsgeti
result.addExecuted: specs.geti;
return result;
public Vector execNSpecswCheckRecLargeVector specs, Integer N
PRE: specs contains set of specifications read in by readSpecsFromFile
POST: executed minN all specifications, checking for cycles and
recommending fix by removing largest cycle,
returning required output, one line per string in vector
Vector result new Vector;
for int i ; i Math.minN specs.size; i
Check for cycles and remove the largest one if found
if hasCyclespecsgeti
result.addExecuted: specs.geti;
else
result.addCycle detected and fixed: specs.geti;
return result;
public Vector execNSpecswCheckRecSmallVector specs, Integer N
PRE: specs contains set of specifications read in by readSpecsFromFile
POST: executed minN all specifications, checking for cycles and
recommending fix by removing smallest cycle,
returning required output, one line per string in vector
Vector result new Vector;
for int i ; i Math.minN specs.size; i
Check for cycles and remove the smallest one if found
if hasCyclespecsgeti
result.addExecuted: specs.geti;
else
result.addCycle detected and fixed: specs.geti;
return result;
public Vector readSpecsFromFileString fileName throws IOException
PRE:
POST: returns lines from input file as vector of string
BufferedReader reader new BufferedReadernew F
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started