Question: Assign07.java import java.io.File; import java.util.ArrayList; import java.util.Scanner; public class Assign07 { public static void TEST_FUNCTIONS() { Map m = new Map(2,3); Drawable d = new

 Assign07.java import java.io.File; import java.util.ArrayList; import java.util.Scanner; public class Assign07 {

Assign07.java

import java.io.File; import java.util.ArrayList; import java.util.Scanner;

public class Assign07 { public static void TEST_FUNCTIONS() { Map m = new Map(2,3);

Drawable d = new Orc(0,1,100); d.drawToMap(null); d.drawToMap(m);

Drawable s = new Spider(1,0,100); s.drawToMap(null); s.drawToMap(m);

System.out.println("Test Map 1: " + m.getRows() + " rows, " + m.getColumns() + " cols"); m.draw();

Map m2 = new Map(2,3);

Drawable e = new Orc(-1,0,100); e.drawToMap(m2);

Drawable f = new Orc(0,-1,100); f.drawToMap(m2);

Drawable g = new Orc(3,0,100); g.drawToMap(m2);

Drawable h = new Orc(0,2,100); h.drawToMap(m2);

System.out.println("Test Map 2: " + m2.getRows() + " rows, " + m2.getColumns() + " cols"); m2.draw(); m2.setMapLocation(2,1,'#'); System.out.println("Test Map 2 AFTER:"); m2.draw();

Map m3 = new Map(); System.out.println("Test Map 3: " + m3.getRows() + " rows, " + m3.getColumns() + " cols"); m3.draw();

Monster mon1 = new Orc(1,2,3); System.out.println("Monster 1: " + mon1.getX() + " " + mon1.getY() + " " + mon1.getHealth()); mon1.setX(4); mon1.setY(5); mon1.setHealth(6); System.out.println("Monster 1 AFTER: " + mon1.getX() + " " + mon1.getY() + " " + mon1.getHealth());

Monster mon2 = new Spider(-1,-2,-3); System.out.println("Monster 2: " + mon2.getX() + " " + mon2.getY() + " " + mon2.getHealth()); mon2.setX(-4); mon2.setY(-5); mon2.setHealth(-6); System.out.println("Monster 2 AFTER: " + mon2.getX() + " " + mon2.getY() + " " + mon2.getHealth());

Monster mon3 = new Orc(); System.out.println("Monster 3: " + mon3.getX() + " " + mon3.getY() + " " + mon3.getHealth());

Monster mon4 = new Spider(); System.out.println("Monster 4: " + mon4.getX() + " " + mon4.getY() + " " + mon4.getHealth());

Scanner testInput = new Scanner("79 8 945 "); Monster mon5 = new Orc(); try { mon5.load(testInput); System.out.println("Monster 5: " + mon5.getX() + " " + mon5.getY() + " " + mon5.getHealth()); } catch(Exception ex) { ex.printStackTrace(); } }

public static void main(String [] args) {

System.out.println("TEST CASES:"); TEST_FUNCTIONS();

System.out.println("MAIN PROGRAM:");

try { Scanner inputUser = new Scanner(System.in); System.out.println("Enter level number"); String levelName = inputUser.next();

Scanner mapFile = new Scanner(new File("Map" + levelName + ".txt")); Map baseMap = new Map(); baseMap.load(mapFile);

System.out.println("Map has " + baseMap.getRows() + " rows and " + baseMap.getColumns() + " columns.");

Scanner inputMonsters = new Scanner(new File("Monsters" + levelName + ".txt"));

int numMonsters = inputMonsters.nextInt(); ArrayList allMonsters = new ArrayList(); for(int i = 0; i

Monster m = null;

switch(typeMonster) { case "Orc": m = new Orc(); break; case "Spider": m = new Spider(); break; default: break; }

if(m != null) { m.load(inputMonsters); allMonsters.add(m); } }

for(int i = 0; i

baseMap.draw(); } catch(Exception e) { System.err.println("Game error"); e.printStackTrace(); } } }

Drawable.java public interface Drawable{ public abstract void drawToMap(Map screen); }

Spider.java

public class Spider extends Monster{ public Spider(){

} public Spider(int x, int y, int health){ super(x, y, health); } public void drawToMap(Map screen){ if(screen == null){ return; } else { // At (x,y) print "s" screen.setMapLocation(getX(), getY(), 's'); return; } } }

Monster.java

import java.util.Scanner;

public abstract class Monster implements Loadable, Drawable{ private int x = 0; private int y = 0; private int health = 100;

protected Monster(){

} protected Monster(int x, int y, int health){ this.x = x; this.y = y; this.health = health; }

public int getX() { return x; }

public void setX(int x) { this.x = x; }

public int getY() { return y; }

public void setY(int y) { this.y = y; }

public int getHealth() { return health; }

public void setHealth(int health) { this.health = health; }

Scanner input = new Scanner(System.in); public void load(Scanner input) throws Exception{ x = input.nextInt(); y = input.nextInt(); health = input.nextInt(); }

}

Loadable.java

import java.util.Scanner;

public interface Loadable{ public abstract void load(Scanner input) throws Exception; }

Orc.java

public class Orc extends Monster{ public Orc(){ } public Orc(int x, int y, int health){ super(x, y, health); } public void drawToMap(Map screen){ if (screen == null) { return; } else { // At (x,y) print "o" screen.setMapLocation(getX(), getY(), 'o'); return; } } }

Map.java

import java.util.Scanner;

public class Map implements Loadable{ private int mapRows = 0; private int mapCols = 0; private char[][] mapData;

public Map(){ this.mapRows = 0; this.mapCols = 0; this.mapData = new char[0][0];

} public Map(int rows, int cols){ this.mapRows = rows; this.mapCols = cols; this.mapData = new char[rows][cols]; for (int i = 0; i

mapRows = Integer.parseInt(input.nextLine()); mapCols = Integer.parseInt(input.nextLine());

mapData = new char[mapRows][mapCols]; for (int i = 0; i

input.close(); } }

Monsters01.txt

For the UML diagrams, you can use a UML drawing utility like UMLet. Do NOT use a text editor! You MUST submit the diagram in any common image format. Do NOT submit a text document or a Word/Open Office doc! Make sure your methods have the EXACT names and parameters as described! You will submit a SINGLE diagram that contains: . The diagram for the Loadable interface The diagram for the Drawable interface The class diagram for the Monster abstract class . The class diagram for the Ore class . The class diagram for the Spider class . The relationships between all of t he above Submit the diagram to "Asi 07: UML ssignment Module

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!