This document is subject to copyright and other intellectual property rights.
Modification, distribution or reposting of this document is prohibited.
Submission Requirements:
1. Code Submission:
● Submit a file called A2FirstName.kt for example: A2Kevin.kt
● The file should contain all the necessary classes and main() function for the application.
2. Code Output
● Submit a screenshot displaying the output of the program’s main() function
Academic Integrity:
● This is an individual assessment
● You are permitted to refer to the Internet for Kotlin syntax. However, following tutorials, homework help websites, or using full/partial solutions from the internet is not permitted
● You are not permitted to share code/references with other learners, or discuss
solutions/approaches.
Problem Description.
Object oriented programming is commonly used to do empirical investigation of real world business domains by creating simulations.
This simulation will model basic space combat between Federation and Romulan ships.
Note: It is not a grading rubric requirement, but - It would be quite helpful for you to get started by sketching out some UML diagrams:
Class Interaction to visualize COMPOSITIONAL Relationships. This includes shared field composition and inheritance.
Object Interaction Diagrams: How are objects communicating via METHOD CALLS : parameters being passed, and return values.
Composition relationships (Spaceship has a Weapon and a Shield).
Dependencies (SpaceBattleSimulator and BattleReport depend on Spaceship).
This diagram illustrates the structure of the system, showing how the different components relate to each other through inheritance, implementation, and composition.
Starter Code:
interface Weapon {
var power: Int
fun fire(): Int
}
interface Shield {
var power: Int
fun absorb(damage: Int): Int
}
interface Spaceship {
val name: String
val weapon: Weapon
val shield: Shield
var isDestroyed: Boolean
fun takeDamage(damage: Int)
}
interface BattleSimulator {
fun simulate(federation1: Spaceship, federation2: Spaceship, romulan1: Spaceship, romulan2: Spaceship)
}
interface BattleReporter {
fun reportBattle(federation1: Spaceship, federation2: Spaceship, romulan1: Spaceship, romulan2: Spaceship)
}
class Phaser(override var power: Int) : Weapon {
override fun fire(): Int {
val damage = maxOf(power / 10, 1)
power -= damage
return damage
}
}
class DeflectorShield(override var power: Int) : Shield {
override fun absorb(damage: Int): Int {
val absorbed = minOf(power, damage)
power -= absorbed
return damage - absorbed
}
}
abstract class AbstractSpaceship(
override val name: String,
weaponPower: Int,
shieldPower: Int
) : Spaceship {
override val weapon = Phaser(weaponPower)
override val shield = DeflectorShield(shieldPower)