Answered step by step
Verified Expert Solution
Link Copied!

Question

00
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 1 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 readSpecsFromFile(String fInName) throws IOException {
// PRE: -
// POST: returns lines from input file as vector of string
[CODE PROVIDED]
}
public Vector readSolnFromFile(String 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 string-match 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.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;
public class BuildSpellbook {
public final Integer MAXCOMS =1000; // maximum number of specs
// Attributes
private Vector specs;
public BuildSpellbook(){
// Constructor
specs = new Vector<>();
}
public Vector execNSpecs(Vector specs, Integer N){
// PRE: specs contains set of specifications read in by readSpecsFromFile()
// POST: executed min(N, all) specifications,
// returning required output, one line per string in vector
Vector result = new Vector<>();
for (int i =0; i < Math.min(N, specs.size()); i++){
result.add("Executed: "+ specs.get(i));
}
return result;
}
public Vector execNSpecswCheck(Vector specs, Integer N){
// PRE: specs contains set of specifications read in by readSpecsFromFile()
// POST: executed min(N, 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 =0; i < Math.min(N, specs.size()); i++){
// Check for cycles (dummy check for illustration)
if (!hasCycle(specs.get(i))){
result.add("Executed: "+ specs.get(i));
}
}
return result;
}
public Vector execNSpecswCheckRecLarge(Vector specs, Integer N){
// PRE: specs contains set of specifications read in by readSpecsFromFile()
// POST: executed min(N, 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 =0; i < Math.min(N, specs.size()); i++){
// Check for cycles and remove the largest one if found
if (!hasCycle(specs.get(i))){
result.add("Executed: "+ specs.get(i));
} else {
result.add("Cycle detected and fixed: "+ specs.get(i));
}
}
return result;
}
public Vector execNSpecswCheckRecSmall(Vector specs, Integer N){
// PRE: specs contains set of specifications read in by readSpecsFromFile()
// POST: executed min(N, 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 =0; i < Math.min(N, specs.size()); i++){
// Check for cycles and remove the smallest one if found
if (!hasCycle(specs.get(i))){
result.add("Executed: "+ specs.get(i));
} else {
result.add("Cycle detected and fixed: "+ specs.get(i));
}
}
return result;
}
public Vector readSpecsFromFile(String fileName) throws IOException {
// PRE: -
// POST: returns lines from input file as vector of string
BufferedReader reader = new BufferedReader(new F

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions