Question: Design requirement: 1 . Keep the Java layer abstracted from your code. 2 . ScannerWrapper should be a singleton that sets up a Scanner and

Design requirement: 1. Keep the Java layer abstracted from your code. 2. ScannerWrapper should be a singleton that sets up a Scanner and has a nextLine() method to leverage Scanners nextLine() method. 3. SystemWrapper should be a singleton that has a println() method to leverage System.out.println()4. Dependency inversion dictates that the singletons should be passed in to the classes that need them. Input needs both. Output needs only SystemWrapper. For this assignment, pass them in through the method, not setters or constructor (we will change this in the next assignment). Since MasterControl needs both Input and Output, MasterControl also needs both singletons. This means that something needs to pass them in to MasterControl (the main method should).
Input: Method signature change: public List read(ScannerWrapper scannerWrapper, SystemWrapper systemWrapper) Remove any throws from the method signature that may be left over from A1.
Output: Method signature change: public void write(List lines, SystemWrapper systemWrapper) Remove any throws from the method signature that may be left over from A1.
MasterControl: Method signature change: public void start(ScannerWrapper scannerWrapper, SystemWrapper systemWrapper) Main method, given to you for free:
Public static void main(String[] args) throws IOException{
MasterControl masterControl = new MasterControl();
masterControl.start(ScannerWrapper.getInstance(), SystemWrapper.getInstance());}
Input Code:
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class Input {
public List read() throws IOException {
return Files.readAllLines(Paths.get("kwic.txt"));
}
}
Output Code:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
public class Output {
public void write(List lines) throws IOException {
try (BufferedWriter writer = new BufferedWriter(new FileWriter("kwic_output.txt"))){
for (String line : lines){
writer.write(line);
writer.newLine();
}
}
}
}
MasterControl Code:
import java.io.IOException;
import java.util.List;
public class MasterControl {
public static void main(String[] args){
MasterControl masterControl = new MasterControl();
masterControl.start();
}
public void start(){
try {
Input input = new Input();
CircularShifter circularShifter = new CircularShifter();
Alphabetizer alphabetizer = new Alphabetizer();
Output output = new Output();
List lines = input.read();
List shiftedLines = circularShifter.shiftLines(lines);
List sortedLines = alphabetizer.sort(shiftedLines);
output.write(sortedLines);
} catch (IOException e){
e.printStackTrace();
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!