Answered Essay: Write an application that tracks information about monster attacks.

Write an application that tracks information about monster attacks.

Use Console I/O (Scanners and System.out) for all input/output in this lab.

For this lab you will create a MonsterAttack class that represents one monster attack, an AttackMonitor class that aggregates data about attacks, and an MonsterAttackDriver class that instantiates an AttackMonitor. One of the key functions of AttackMonitor is to read and write data using a text file, but you will complete this part in a future lab. Note that nearly all the methods in AttackMonitor and MonsterAttack will be instance, not static, methods.

Part I – MonsterAttack class

Each object of this class represents information about a single attack. The data on each attack includes an integer attack id, three ints representing the day of the month, the month, and the year of the attack, the name of the monster involved (assume that each attack involves only one monster), the location of the attack (String), and the name of the person reporting the attack (String).

MonsterAttack needs a constructor that sets all the instance fields listed above using its parameters. It should take the three components of the date as a single String in the format MM/DD/YYYY (eg, 01/31/2010). Use String’s split method to split this String on the slashes, parse the resulting Strings to ints, and use them to set the values of the month, day, and year.

Monster attack also needs getters and setters for all the data fields and a toString() that uses the instance data to create and return a String similar to this: “Attack # 125: Godzilla attacked Tokyo on 6/25/2009. Reported by Kyohei Yamane.”

Part II – AttackMonitor

Create an AttackMonitor class that keeps track of the MonsterAttack objects. It should contain an array list (not an array) of MonsterAttacks and an instance method called monitor() with a menu that allows the user to choose to quit or to do any of the tasks listed below, which must all be implemented in separate methods. After doing any of these tasks, the program should return to the menu, so that the user can continue working on any series of tasks until he/she chooses to quit. Write instance, not static, methods to do each of the following:

Input information on a MonsterAttack. Get the data from the user, call the MonsterAttack constructor using the input data as arguments, and add the new attack to the list of attacks.

Show the current list of attacks by iterating through the list, calling the toString() of each attack, and outputting the result. Write this method so that the program does not crash if the list is empty.

Choose an attack from the array list and delete it. The easiest way to do this is to call the method that shows the information, then ask the user for the id number of the attack to delete. Use linear search to find the attack with that id and delete it. The id number may not be the same as the index in the list. Make sure the application does not crash if the user enters an id that does not appear in the list.

AttackMonitor must also have a method to create a MonsterAttack using method parameters and add it to the list. In other words, this method will take parameters for the data fields, rather than taking them as user input. You will call this method from the Driver to create test data without needing to type it.

Part III: MonsterAttackDriver

The driver class should instantiate an AttackMonitor and call its monitor() method.

In order to make the application easier to test, the driver should provide hard coded data on three attacks. Use the data to create the three attacks and add them to the list in the monitor. Use a separate method for this and call it from main().

Turn in your .java files and a working executable .jar. If your .jar does not work, you will need to create a new one, and the entire assignment will be treated as late.

Expert Answer




//package MonsterTime;

public class MonsterAttackDriver {
public static void main(String[] args) {
AttackMonitor getDestroyed = new AttackMonitor();

//package MonsterTime;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

public class AttackMonitor {

private List<MonsterAttack> monsterAttacks = new ArrayList<MonsterAttack>();

public void monitor() {

String[] options = { “Quit”, “Input a New Monster Attack”, “Show List of Attacks”, “Delete an Attack” };

int selection;

do {

selection = JOptionPane.showOptionDialog(null, “What would you like to do?”, “Main Menu”,
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null);

switch (selection) {

case 1:
case 2:
if (!(monsterAttacks.isEmpty()))
else if (monsterAttacks.isEmpty())
JOptionPane.showMessageDialog(null, “There are no Monster Attacks.”);
case 3:
if (!(monsterAttacks.isEmpty()))
else if (monsterAttacks.isEmpty())
JOptionPane.showMessageDialog(null, “There is nothing to delete.”);

} while (selection != 0);

private void addMonsterAttack() {

int attackIdIn = Integer.parseInt(JOptionPane.showInputDialog(“Please Enter the Attack ID #: “));

String monsterNameIn = JOptionPane.showInputDialog(“Please Enter the Monster Name: “);

String fullDateIn = JOptionPane.showInputDialog(“Please Enter the Date the attack occured on (MM/DD/YYYY): “);

int attackVictimsIn = Integer.parseInt(JOptionPane.showInputDialog(“How many fatalities were there? “));

String attackLocationIn = JOptionPane.showInputDialog(“Where did this happen? “);

monsterAttacks.add(new MonsterAttack(fullDateIn, attackIdIn, attackVictimsIn, monsterNameIn, attackLocationIn));


private void showMonsterAttacks() {

String wholeList = “”;

for (int i = 0; i < monsterAttacks.size(); i++)
wholeList += monsterAttacks.get(i);

JOptionPane.showMessageDialog(null, wholeList);


private void deleteMonsterAttack() {


int choice = Integer.parseInt(
JOptionPane.showInputDialog(“Enter the ID # of the Monster attack you would like to delete: “));

for (int i = 0; i < monsterAttacks.size(); i++) {
if (choice == monsterAttacks.get(i).getAttackId())


//package MonsterTime;

public class MonsterAttack {
private int attackId;
private int attackDay;
private int attackMonth;
private int attackYear;
private int attackVictims;
private String monsterName;
private String attackLocation;
private String fullDate;

public MonsterAttack(String fullDateIn, int attackIdIn, int attackVictimsIn, String monsterNameIn,
String attackLocationIn) {

attackId = attackIdIn;
attackVictims = attackVictimsIn;
monsterName = monsterNameIn;
attackLocation = attackLocationIn;
fullDate = fullDateIn;

public String getFullDate() {
return fullDate;

public void setFullDate(String fullDate) {
this.fullDate = fullDate;

public int getAttackId() {
return attackId;

public void setAttackId(int attackId) {
this.attackId = attackId;

public int getAttackDay() {
return attackDay;

public void setAttackDay(int attackDay) {
this.attackDay = attackDay;

public int getAttackMonth() {
return attackMonth;

public void setAttackMonth(int attackMonth) {
this.attackMonth = attackMonth;

public int getAttackYear() {
return attackYear;

public void setAttackYear(int attackYear) {
this.attackYear = attackYear;

public int getAttackVictims() {
return attackVictims;

public void setAttackVictims(int attackVictims) {
this.attackVictims = attackVictims;

public String getMonsterName() {
return monsterName;

public void setMonsterName(String monsterName) {
this.monsterName = monsterName;

public String getAttackLocation() {
return attackLocation;

public void setAttackLocation(String attackLocation) {
this.attackLocation = attackLocation;

public void fullDateSplitter(String fullDate) {

String[] afterSplit = fullDate.split(“/”);

attackDay = Integer.parseInt(afterSplit[0]);
attackMonth = Integer.parseInt(afterSplit[1]);
attackYear = Integer.parseInt(afterSplit[2]);


public String toString() {


return “Attack # ” + attackId + ” occured on ” + attackDay + “/” + attackMonth + “/” + attackYear + “. ”
+ monsterName + ” attacked ” + attackLocation + “, resulting in ” + attackVictims
+ ” tragic fatalities.” + “n”;



Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.


Let us write that nagging essay.


Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.


Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.


Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.


Receive your Paper

After Editing, your paper will be sent to you via email.