I'm very new to programming and Java just so you know...
I'm working on a code/program skeleton (assignment in school) which has the following description implement and test a skeleton for a command-controlled program and it is intended to be used to keep track of the dogs at a dog day, and the commands that the program must accept at the first stage are as follows: -register new dog -increase age -list dogs -remove dog -exit
The only one of these commands that should work correctly is exit that should print a message that the program is terminated and then terminate the program. This must be done by closing the command line, and not by System.exit, which must not be used. The other commands should only print a short text that tells which command was specified. This text must contain the full command name as above so that the test program can identify them. One tip is to also accept other, shorter, commands so that your own testing becomes easier."
One of the non-functional requirements is that no static methods or variables may be used except on the main string.
My question is therefore; HOW can I remove the static methods from my program skeleton? I have a really hard time understanding this!
import java.util.Scanner;
public class ProgramSkeleton {
static Scanner input = new Scanner(System.in);
public static void initialize() {
System.out.println("Welcome to the dog register!");
System.out.println("Write 0 to register new dog");
System.out.println("Write 1 to increase age");
System.out.println("Write 2 to list dogs");
System.out.println("Write 3 to remove dog");
System.out.println("Write 4 to exit");
}
public static void runCommandLoop() {
boolean done;
do {
String command = readCommand();
done = handleCommand(command);
} while (!done);
}
public static String readCommand() {
System.out.print("> ");
String command = input.nextLine();
return command;
}
private static boolean handleCommand(String command) {
switch (command) {
case "0":
case "register new dog":
System.out.println("You have chosen register new dog.");
return true;
case "1":
case "increase age":
System.out.println("You have chosen increase age.");
return true;
case "2":
case "list dogs":
System.out.println("You have chosen list dogs.");
return true;
case "3":
case "remove dog":
System.out.println("You have chosen remove dog.");
return true;
case "4":
break;
default:
System.out.println("unknown command");
return false;
}
return false;
}
public static void closeDown() {
System.out.println("Goodbye!");
}
public static void main(String[] args) {
initialize();
runCommandLoop();
closeDown();
}
}