都是实际开发逼出来的吧。
人类真灵活~~~~:)
就是将整个功能的实现在编程时,打散到一个一个文件中,提前写好核心算法,
在TEAM的实现方案确定下来之后,再进行组装。
GuessGame.java
package cc.openhome; public abstract class GuessGame { public void go() { int Number = (int) (Math.random() * 10); int guess; do { print("Please input number: "); guess = nextInt(); } while (guess != Number); println("Bingo"); } public abstract void print(String text); public abstract void println(String text); public abstract int nextInt(); }
ConsoleGuessGame.java
package cc.openhome; import java.util.Scanner; public class ConsoleGuessGame extends GuessGame { private Scanner scanner = new Scanner(System.in); @Override public void print(String text) { System.out.print(text); } @Override public void println(String text) { System.out.println(text); } @Override public int nextInt() { return scanner.nextInt(); } }
Guess.java:
package cc.openhome; public class Guess { public static void main(String[] args) { GuessGame game = new ConsoleGuessGame(); game.go(); } }
时间: 2024-10-26 12:07:38