Code
package NumberReader.IntegerReader;
import NumberReader.INumberReaderConfig;
import NumberReader.NumberNotFoundException;
public class AdditivePromptlessIntegerReader extends PromptlessIntegerReader {
public AdditivePromptlessIntegerReader(INumberReaderConfig config)
{
super(config);
}
public void readNumbers() {
int sum = 0;
while(true)
{
try
{
sum += readNumber("");
}catch(NumberNotFoundException nnfe)
{
break;
}
}
out.println(sum);
}
}
Code
package NumberReader.IntegerReader;
import NumberReader.NumberReaderApplicationBase;
public class AdditivePromptlessIntegerReaderApplication extends NumberReaderApplicationBase
{
AdditivePromptlessIntegerReaderApplication()
{
super(new AdditivePromptlessIntegerReaderFactory(), new StaticIntegerReaderConfig());
}
}
Code
package NumberReader.IntegerReader;
import NumberReader.INumberReader;
import NumberReader.INumberReaderConfig;
import NumberReader.INumberReaderFactory;
public class AdditivePromptlessIntegerReaderFactory implements INumberReaderFactory {
public INumberReader createNumberReader(INumberReaderConfig config) {
return new AdditivePromptlessIntegerReader(config);
}
}
This can be executed using the following Driver, using dependency injection to wire up the application for use
Code
package NumberReader.IntegerReader;
public class AdditivePromptlessIntegerReaderApplicationDriver
{
public static void main(String[] args)
{
new AdditivePromptlessIntegerReaderApplication().execute();
}
}
Edit: You may notice that I used an exception to modify control logic. This is poor design. If it is beneficial to you, I can refactor this immediately to provide a more robust solution to your problem.
This post was edited by Minkomonster on Dec 15 2014 10:19pm