Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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: Keep the Java layer abstracted from your code. ScannerWrapper should be a singleton that sets up a Scanner and has a nextLine method to leverage Scanners nextLine method. SystemWrapper should be a singleton that has a println method to leverage System.out.println 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 readScannerWrapper scannerWrapper, SystemWrapper systemWrapper Remove any throws from the method signature that may be left over from A
Output: Method signature change: public void writeList lines, SystemWrapper systemWrapper Remove any throws from the method signature that may be left over from A
MasterControl: Method signature change: public void startScannerWrapper scannerWrapper, SystemWrapper systemWrapper Main method, given to you for free:
Public static void mainString args throws IOException
MasterControl masterControl new MasterControl;
masterControl.startScannerWrappergetInstance SystemWrapper.getInstance;
Input Code:
import java.ioIOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class Input
public List read throws IOException
return Files.readAllLinesPathsgetkwictxt;
Output Code:
import java.ioBufferedWriter;
import java.ioFileWriter;
import java.ioIOException;
import java.util.List;
public class Output
public void writeList lines throws IOException
try BufferedWriter writer new BufferedWriternew FileWriterkwicoutput.txt
for String line : lines
writer.writeline;
writer.newLine;
MasterControl Code:
import java.ioIOException;
import java.util.List;
public class MasterControl
public static void mainString 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.shiftLineslines;
List sortedLines alphabetizer.sortshiftedLines;
output.writesortedLines;
catch IOException e
eprintStackTrace;
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