forked from divScorp/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyShipTesting.java
More file actions
32 lines (26 loc) · 821 Bytes
/
EnemyShipTesting.java
File metadata and controls
32 lines (26 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package designPattern.Factory;
import java.util.Scanner;
public class EnemyShipTesting {
public static void main(String[] args) {
// Create the factory object
EnemyShipFactory shipFactory = new EnemyShipFactory();
// Enemy ship object
EnemyShip theEnemy = null;
Scanner userInput = new Scanner(System.in);
System.out.print("What type of ship? (U / R / B)");
if (userInput.hasNextLine()) {
String typeOfShip = userInput.nextLine();
theEnemy = shipFactory.makeEnemyShip(typeOfShip);
if (theEnemy != null) {
doStuffEnemy(theEnemy);
} else
System.out.print("Please enter U, R, or B next time");
}
userInput.close();
}
public static void doStuffEnemy(EnemyShip anEnemyShip) {
anEnemyShip.displayEnemyShip();
anEnemyShip.followHeroShip();
anEnemyShip.enemyShipShoots();
}
}