Answered step by step
Verified Expert Solution
Link Copied!

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: 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

2. How will you handle the situation?

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago