Question
When you read through the class youll see that it prompts the user for a command (create, list, get, update, remove, exit) and then prompts
When you read through the class youll see that it prompts the user for a command (create, list, get, update, remove, exit) and then prompts the user for additional information. The List command should number the addresses starting at 0 so that the Get, Update and Remove commands know which address to operate on. For simplicity the Address constructor will take a list of fields in order and create addresses based on that.
The Address Book class should store the addresses and, as you can see from the class diagram, provide methods to manipulate them. The individual Command subclasses are responsible for calling the appropriate method of the Address Book instance thats passed into the runCommand() method.
The main method in AddressBookMain should create the Address Book and CommandReader instance, and then keep requesting Commands from the CommandReader until the latter returns null (which signals that the user requested exit).
You may only write to the console using System.out and System.err (and friends) in order to interact with the user. Any debugging or other logging statements you wish to write must be written using a Logger as described in the reading. Your application must include some logging setup and at least one log statement.
You must also write a unit test class for the AddressBook class that fully tests the AddressBook class.
You should submit all the code for this assignment, along with a PDF write-up, in a single zip file. The structure of your code should match the package structure of the classes and you should include all relevant code for this assignment so that it is independent of your other submissions.
import java.io.PrintWriter; import java.io.Reader; import java.util.ArrayList; import java.util.List; import java.util.Scanner;
public class CommandReader { private static final int LENGTH = 7; private final Scanner scanner; private final PrintWriter output;
public CommandReader(Reader input, PrintWriter output) { scanner = new Scanner(input); scanner.useDelimiter(System.lineSeparator()); this.output = output; }
public Command readNext() { String command; do { output.print("Please enter the command [create, get, list, update, remove, exit]: "); output.flush(); command = scanner.next();
if (command.toLowerCase().equals("list")) { return new ListAddresses(); }
if (command.toLowerCase().equals("get")) { return new GetAddress(getNumber()); } if (command.toLowerCase().equals("remove")) { return new RemoveAddress(getNumber()); }
if (command.toLowerCase().equals("create")) { return new CreateAddress(getArgs()); }
if (command.toLowerCase().equals("update")) { return new UpdateAddress(getNumber(), getArgs()); }
} while (!command.toLowerCase().equals("exit")); return null; }
private List
for (String arg : line.split(", *")) { args.add(arg); }
while (args.size() < LENGTH) { args.add(""); } return args; }
private int getNumber() { output.print("Which address? Please enter a number: "); output.flush(); return scanner.nextInt(); }
}
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