Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Files: OceanWars Main Program Ship Abstract Class ShipType Enumeration SmallShip Inherits from Ship MediumShip Inherits from Ship implements IFighter BigShip Inherits from Ship implements IFighter

Files:

OceanWars Main Program

Ship Abstract Class

ShipType Enumeration

SmallShip Inherits from Ship

MediumShip Inherits from Ship implements IFighter

BigShip Inherits from Ship implements IFighter

Person Abstract Class

Passenger Inherits from Person

Soldier Inherits from Person implements IFighter

Pirate Inherits from Person implements IFighter

IFighter Interface

OceanWars:

Has an array of Ship objects

Ship:

Abstract class that has an array of Person objects

Has a enushipName string variable

Has a ShipType variable

Create a workhorse constructor

enuShipType:

An enumeration of ship types

Stores: (string) friendlyName, (int) maxAllowedPeople, (int) damage, (int) weightAdd 3 ship types:

FIRE_SHIP ("Fire Ship", 70, 500, 20000)

CUTTER ("Cutter", 10, 5, 600)

TRIREME ("Trireme", 140, 800, 21000)

SmallShip:

Class that inherits from Ship

MediumShip / BigShip:

Classes that inherit from Ship and implements the IFighter interface

Person:

Simply an abstract class that stores the first and last name of the person

Passenger:

Class that inherits from Person

Soldier / Pirate:

Classes that inherit from Person and implement the IFighter

IFighter:

A user defined interface with one declared method: attack(IFighter opp)

Download the starting file: OceanWars.java from Canvas and add it to your project. Complete the lab by following the directions given in the file. Create a Java application containing all of the above components with the following rules:

When a Soldier or Pirate are told to attack make sure the opponent (opp) is not a ship. Also, opp cannot attack anyone that doesnt fight

The same goes for a BigShip and MediumShip. Ships can only attack ships but not ships that dont fight

Properties in classes need to have getters and setters

Person needs to have 1 constructor that accepts a first name and a last name

Ship needs to have 1 constructor that accepts a ship name and enuShipType

how do I create a fighter method, what should I type in oceanwar class?

here is the oceanwar:

import java.util.ArrayList;

public class OceanWars {

private static ArrayList ships = new ArrayList();

public static void main(String[] args) {

//=====================================================================================

// Create a BigShip variable called enemyShip of type TRIREME and has the name of "Evil Thor"

// using a loop add 20 Passengers - the passenger's first name should be "Passenger" and the last name can be the loop counter (e.g., Passenger-1)

// using a loop add 50 Pirates - the pirate's first name should be "Pirate" and the last name can be the loop counter (e.g., Pirate-1)

//=====================================================================================

// Create a MediumShip variable called friendShip of type TRIREME and has the name "The Good Guys"

// using a loop add 10 Passengers - the passenger's first name should be "Passenger" and the last name can be the loop counter

// using a loop add 100 Soldiers - the soldier's first name should be "Soldier" and the last name can be the loop counter

//=====================================================================================

// Create a SmallShip variable called neutralShip of type CUTTER. Name it "Cut The Wave"

// using a loop add as many Passengers as you can without exceeding it's limit

// Now, add the 3 ships to your ships array list

// Call the releasePassengers(...) method below 3 times sending each of the ships you created

// Print the total number of enemyShip, friendShip, and neutralShip people that are left

System.out.printf("The total number of people left on all ships is: %d ", -1 );

// Write the code that will call upon getShipByType and send it the TRIREME type

// loop through the array list that is returned from the method and print the ship's name

}

//=====================================================================================

// Write the code that will fill and return an ArrayList of ships that are fighters

private static ArrayList getAllFightingShips() {

ArrayList ret = new ArrayList();

return ret;

}

//=====================================================================================

// Write the code that will release all people from a ship that are marked as Passenger

private static int releasePassengers(Ship s) {

int ret = 0;

return ret;

}

//=====================================================================================

// Write the code that will fill and return an ArrayList of ships by a given type

private static ArrayList getShipByType(ShipType st) {

ArrayList ret = new ArrayList();

return ret;

}

}

can someone help me with this program?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

119. If X is uniformly distributed on [1, 1], find the pdf of Y X2.

Answered: 1 week ago

Question

Describe new developments in the design of pay structures. page 475

Answered: 1 week ago