Project 2 :Star Wars Simulation

Original price was: $40.00.Current price is: $35.00.

Rate this product

CmpE 160, Introduction to Object Oriented Programming
Project 2 :Star Wars Simulation
1 Introduction
Hi, there. Welcome to the second project where you will be learning the fundamentals of OOP. In this Star
Wars themed project you are going to simulate some events. The main objective is to analyze the requests
provided in input and carry out the necessary actions. It is also possible to earn bonus score if you can find
an optimized way of simulating Assault event. Even though the theme is Star-Wars, please do not assume
anything related to the original Star Wars to be true unless the project clearly states it (ie. Normally there can
be at most 2 Sith at the same time in Star-Wars Universe but in this project there can be many.)
In this Star Wars setup, there are two organizations in conflict. Simply, the good side is called Republic and
the evil side is called Separatists. Besides that, we have mainly three entities (Sector, Warship and Crewman)
and their respective subclasses.
A sector is an area of space affiliated with one of the two organizations. Each sector can be represented as a
horizontal line so warship locations can be described by giving a sector and an x-coordinate (since there is only
one coordinate we will just say coordinate instead of x-coordinate). Each sector has three properties
• Id (will be unique for each sector)
• Name
• Affiliation
Crewman is an abstract class that covers all personnel types which includes Generals and Officers. Generals
are candidates of warship commanders and they can use Force (a special ability to do fancy stuff like moving
objects). General is also an abstract class and has two subclasses as Jedi and Sith. A warship can only be
commanded either by a Jedi (a republic warship) or a Sith (a separatist warship). Officers are crewmen that
have an intrinsic in one of the 5 areas (TACTICAL,PILOTING,GUNNERY,ENGINEERING,COMMAND) and
an intrinsic level between 1 and 10, which indicates how good they are at their expertise.
In common, Crewmen have,
• Id
• Name
In the Star Wars universe, the ability of using force of a force user is proportional to user’s midichlorian
level. Since darkside is a pathway to many abilities a Sith can produce more force power then a Jedi with equal
amount of midichlorian. While officers have intrinsic level, Generals have experience. So a General have,
• Experience – (in common)
• Midichlorian – (in common)
• Sanity – (only for Jedi)
• Intelligence – (only for Jedi)
• Persuasion – (only for Sith)
in addition to common Crewman properties.
In this project, Sith will try to convince Jedi to join the dark side. Each Sith has a property of persuasion
that indicates his ability to convince Jedi and Jedi has a property called intelligence to resist the persuasion
tricks of Sith. In addition, Jedi also has a sanity value (initially 100), if a Jedi lost all of his sanity he will join
the darkside.
Officers have following properties
• Intrinsic
• Intrinsic Level
Warship is an abstract class that covers all 4 different warships in this project. There is RepublicCruiser,
a warship used by Republic forces and SeparatistDestroyer, a warship used by Separatist forces. SeparatistDestroyer has two more subclass derived from it called SeparatistFrigate and SeparatistBattleship. So
there is only one type of Republic warship and three types of Separatist warships. Each warship has several
properties in common which are listed below
• Id (will be unique for each warship)
• Name
• Current Sector
• Coordinate
• Affiliation
• Armament Power
• Shield Power
• Crew Capacity
• Crew
In addition, Separatist Destroyers have Escape Pods to evacuate their generals. Some of those properties are
initially constant (Armament and Shield can be upgraded later) and their initial values are given in the table
Class Affiliation Armament
Crew Capacity Escape
REPUBLIC 100 100 10 –
SEPARATISTS 120 100 12 2
SEPARATISTS 400 200 20 3
In a given input file, all entities existing in our universe and a number of events will be given. Your task is
to simulate those events and print out the final state according to the output format which is explained later
in the description. There are necessary fields and methods that you should implement exactly as stated but
remember you can use additional classes/fields/methods in your project.
Also, as a significant remark, the signature of the methods and the field names that you are going to implement
should be identical to the ones that are specified in this document. If a specific method signature is not enforced
by the project description, you can feel free to implement it in your way (i.e. you can implement extra methods
considering your own design choice). However, you should also consider the proper usage of access modifiers for
preserving the desired visibility and accessibility throughout the project. In other words, you should not define
everything as “public”, which results in a penalty if done so.
2 Class Hierarchy And Details
Within the scope of this project, you are expected to create and implement following classes (which will be
explained in detail in the rest of this document):
12. Fig. 1: The class hierarchy that you must consider during the implementation is illustrated in the class diagram above.
Using the fundamentals of the object-oriented programming methodology and the inheritance principles, you
are expected to fill in these files in a suitable manner to complete the project. Do not forget that you are free
to create new packages, classes, or interfaces. However, the class names and properties that are given above
should be exactly the same in your projects. Please note that, if you fail to follow this instruction, you do not
get any points as your projects will be automatically graded.
You are already provided with the following interfaces and enums:
Do not modify the code in these files! You are responsible for all the compilation errors that originated from
the changes made in any of these classes including the addition or removal of libraries.
2.1 Details
The necessary fields and functions of each class are described here. You can use additional fields, functions and
classes but you should implement necessary fields and functions exactly as described here (it is your responsibility
to choose appropriate modifiers).
You are required to read from an input file and print to an output file, names of which are passed to your
program as arguments (args[0] for input file, args[1] for output file). Apart from unit tests to test your code
and class structure, we will use the Main class to test your code for various inputs and outputs.
1 /*
2 * Necessary fields
3 */
4 int id;
5 String name;
6 Affiliation affiliation;
7 /*
8 * Necessary methods
9 */
10 public Sector(int id, String name, Affiliation affiliation);
11 public void assault();
Please briefly explain your approach and analyze your assault function’s complexity in the Javadoc file. This
is important for partial grading. Even if your code fails in bonus cases you might get most of the points.
1 /*
2 * Necessary fields
3 */
4 int id;
5 String name;
6 /*
7 * Necessary methods
8 */
9 public Crewman(int id, String name);
This is an abstract class.
1 /*
2 * Necessary fields
3 */
4 int intrinsicLevel;
5 Intrinsic intrinsic;
6 /*
7 * Necessary methods
8 */
9 public Officer(int id, String name, Intrinsic intrinsic, int intrinsicLevel);
10 public void train();
1 /*
2 * Necessary fields
3 */
4 int experience;
5 int midichlorian;
6 /*
7 * Necessary methods
8 */
9 public General(int id, String name, int experience , int midichlorian);
This is an abstract class that implements IForceUser interface.
1 /*
2 * Necessary fields
3 */
4 int sanity;
5 int intelligence;
6 /*
7 * Necessary methods
8 */
9 public Jedi(int id, String name, int experience, int midichlorian, int
1 /*
2 * Necessary fields
3 */
4 int persuasion;
5 /*
6 * Necessary methods
7 */
8 public Sith(int id, String name, int experience, int midichlorian, int
1 /*
2 * Necessary fields
3 */
4 int id;
5 String name;
6 Sector currentSector;
7 int coordinate;
8 int armamentPower;
9 int shieldPower;
10 int crewCapacity;
11 ArrayList<Crewman> crew;
12 /*
13 * Necessary methods
14 */
15 public Warship(int id,String name, Sector currentSector, int coordinate,
ArrayList<Crewman> crew);
This is an abstract class that implements IWarship interface.
1 /*
2 * Necessary fields
3 */
5 ArrayList<Crewman> captives;
6 /*
7 * Necessary methods
8 */
9 public RepublicCruiser(int id, String name, Sector currentSector, int coordinate
, ArrayList<Crewman> crew);
10 public void visitCoruscant();
1 /*
2 * Necessary fields
3 */
4 int escapePods;
5 /*
6 * Necessary methods
7 */
8 public SeparatistDestroyer(int id, String name, Sector currentSector, int
coordinate, ArrayList<Crewman> crew);
1 /*
2 * Necessary methods
3 */
4 public SeparatistFrigate(int id, String name, Sector currentSector, int
coordinate, ArrayList<Crewman> crew);
1 /*
2 * Necessary methods
3 */
4 public SeparatistBattleship(int id, String name, Sector currentSector, int
coordinate, ArrayList<Crewman> crew);
2.2 Interface Details
1 /*
2 * Adds a crewman to ship if crewman is accepted by the warship.
3 */
4 void addCrewman(Crewman crewman);
6 /*
7 * Removes a crewman if it exist in the warship.
8 */
9 void removeCrewman(Crewman crewman);
11 /*
12 * Relocate the warship’s active sector and coordinate.
13 */
14 void jumpToSector(Sector sector, int coordinate);
16 /*
17 * Returns the power output of the warship.
18 * Described below.
19 */
20 int getPowerOutput();
22 /*
23 * Returns the general of the warship.
24 * Described below.
25 */
26 General getCommander();
27 /*
28 * Increment warship armament power by amount
29 */
30 void upgradeArmament(int amount);
31 /*
32 * Increment warship shield power by amount
33 */
34 void upgradeShield(int amount);
A warship is commanded by either a Sith (Separatist Warships) or a Jedi (Republic Warship). A warship
always has at least 1 general but there can be more. In a Republic Cruiser, the commander is the one with the
highest experience (in case of equality the one with the lower id will become commander). In a Separatist ship
since the dark side only cares about power, the commander is the one who has the highest combat power (in
case of equality the one with the lower id will become the commander). Note that the commander of a warship
can change after some events. Implement getCommander() function that returns the active commander of a
A warship’s power output depends on many factors: Armament Power, Shield Power, Generals’ Contribution,
Officers’ Contribution, and Sector Buff. Generals’ Contribution is the sum of all generals’ combat power who
is in the crew.
Assume there are two generals in the crew whose combat powers are 700 and 900. Then, the Generals’ Contribution is calculated as 1600.
Officers’ Contribution is dependent on the highest intrinsic level of each intrinsic class present in the crew
and calculated by the following formula:
Assume that the following officers are present on the crew: (Piloting, 2) , (Gunnery, 1), (Gunnery, 2), (Engineering, 10). Since there is a better officer with level 2 Gunnery, the other officer who has also Gunnery
class intrinsic does not matter. Also since there are no Command and Tactical officers TACTICAL MAX and
COMMAND MAX are 0. Finally, Officer’s Contribution = (2 + 1) ∗ (2 + 1) ∗ (10 + 1) ∗ (0 + 1) ∗ (0 + 1) = 99.
Sector Buff is a multiplier that changes if a warship is in a sector that is affiliated with the same organization.
If a warship and a sector are affiliated to the same organization, Sector Buff is 3. If they aren’t, Sector Buff is
Finally, to calculate the power output of a warship, use the following formula:
Sector Buff * Armament Power + Shield Power + General’s Contribution + Officer’s Contribution
Assume that there is a Republic Cruiser that has 300 armament power and 300 shield power. There are 2
generals with 700 and 900 combat powers on the crew. Also, there are following officers on the crew: (Piloting,
2), (Gunnery, 1), (Gunnery, 2), (Engineering, 10). If this cruiser is in a Sector that is affiliated with the
Republic, its power output is equal to 3 ∗ (300 + 300 + 1600 + 99) = 6897. If it were in a sector that is affiliated
with Separatists its power output would be 2 ∗ (300 + 300 + 1600 + 99) = 4598
1 /*
2 * Calculates Force Power of a Force user.
3 */
4 int getForcePower();
5 /*
6 * Calculates Combat Power of a Force user.
7 */
8 int getCombatPower();
A force user’s ability to produce force power is directly proportional to his midichlorian level. A Jedi’s
force power is 3 * midichlorian . Since the dark side is a pathway to many abilities, a Sith’s force power is
4 * midichlorian
A Jedi’s combat power is calculated as follows:
Force Power + experience + sanity – 100 + intelligence
A Sith’s combat power is calculated as follows:
Force Power + experience + persuasion
3 Input-Output Format
3.1 Input Format
Input will basically consist of two parts. Firstly, entities will be defined, then an event list will be given in
the second part. Ids of entities are starting from 1 and counted in the order of definition.
In the first line of input, there will be an integer S representing the number of sectors. Following S lines will
contain two strings separated by whitespace: the name of the sector, an uppercase string that indicates the
organization the sector is affiliated with (either REPUBLIC or SEPARATISTS)
• Ryndellia REPUBLIC
There is a sector named Ryndellia and it is affiliated with REPUBLIC
There is a sector named Mygeeto and it is affiliated with SEPARATISTS
In the next line after sector declarations, there will be an integer C representing the number of crewmen.
The following C line will be in one of these three formats
1. Officer Name Intrinsic Intrinsic Level
Intrinsic is an uppercase string representing an officer’s intrinsic and can be one of these followings:
Intrinsic Level is an integer between 1-10 (both including)
• Officer Grievous COMMAND 9
There is an officer named Grievous who has level-9 COMMAND Intrinsic.
2. Jedi Name Experience Midichlorian Intelligence
Experience, Midichlorian, and Intelligence are positive integers.
• Jedi Windu 350 80 70
There is a Jedi named Windu who has 350 experience, 80 midichlorian, and 70 intelligence.
3. Sith Name Experience Midichlorian Persuasion
Experience, Midichlorian, and Persuasion are positive integers.
• Sith Dooku 200 50 125
There is a Sith named Dooku who has 200 experience, 50 midichlorian, and 125 persuasion.
In the next line, there will be an integer W representing the total number of warships. Each warship will be
represented in two lines. First line will be in this format: Class Name Name Current Sector Id Coordinate .
Second line will contain the information of crew of the ship in this format: Crew Size A list of crewman Id’s

SeparatistBattleship Malevolence 3 2
2 1 2
There is a Separatist Battleship named Malevolence located in sector with id-3, coordinate 2. Malevolence has 2 crewmen onboard: Crewman with id-1 and crewman with id-2

RepublicCruiser Halleck 2 1
4 3 4 5 6
There is a Republic Cruiser named Halleck located in sector with id-2, coordinate 1. Malevolence has
4 crewmen onboard: Crewmen with id 3,4,5,6.
In the next line, there will be an integer E representing the total number of events. The following E lines are
representing events. Each line starts with an integer, event code.
• 10 Attacker-Id Defender-Id
Attacker warship attacks defender warship. There won’t be any case where attacker and defender are
allies. It would be either (Separatists Warship, Republic Warship) or (Republic Warship, Separatist Warship).
• 11 Sector-Id
Simulate Assault in given sector. Given Id will always exist.
• 20 Warship-Id Sector-Id Coordinate
Relocate given warship to given sector, given coordinate. Given Ids will always exist.
• 30 Cruiser-Id
Given cruiser visits Corousant. Given Id will always exist.
• 40 Crewman-Id Warship-Id
Add a new crewman to given warship. Note that this operation is not always successful. Crewman may
not be accepted by warship, crewman with given Id might be dead or onboard on another warship, etc.
• 41 Crewman-Id Warship-Id
Remove crewman from given Warship if crewman is a member of the crew.
• 50 Officer-Id
Train officer. Given Id will always exist.
• 51 Warship-Id Armament or Shield Amount
1. 1 Armament 10
Add 10 to armament power of warship-1
2. 2 Shield 10
Add 10 to shield power of warship-2
3.2 Events
Input will consist several events in order. Your program is expected to simulate those events.
Code Name Parameters
10 Attack Attacker Warship Id Defender Warship Id
11 Assault Sector Id
20 Jump To Sector Warship Id Sector Id Coordinate
30 Visit-Corousant Cruiser Id
40 Add-Crewman Crewman Id Warship Id
41 Remove-Crewman Crewman Id Warship Id
50 Train Officer Officer Id
51 Upgrade Warship Warship Id
3.2.1 Attack
Attack is the event of the battle between two warships. Two id will be given Attacker Id Defender Id .
At the beginning of Attacks commanding generals of both sides will have a brief talk with each other. Sith will
try to convince Jedi. After the talk Commander Jedi’s sanity will drop by Sith.persuasion – Jedi.intelligence
(if Jedi has higher intelligence than Sith’s persuasion, sanity will stay the same). If Jedi’s sanity drops to 0,
he will betray and kill every other crew member of his ship and the Cruiser will be destroyed by Separatist
Warship. In the end, the betraying Jedi commander will be killed by the Sith commander.
Even if Sith cannot fully convince the Jedi commander, decreasing his sanity will reduce both the commander
Jedi’s combat power and the Cruiser’s power output. After the talk between commanders if Attacker Warship
has strictly greater power output than Defending Warship, Defending Warship will be destroyed by Attacker
If a Republic Cruiser destroys a Separatist Destroyer, all officers of the separatist destroyer will be taken as
captives (captives do not consume crew capacity so there is no limitation of captive count). Since Siths are too
dangerous to be left alive commander Jedi will try to kill them. If commander Jedi has greater than or equal
combat power to a Sith in Separatist Warship, the commander Jedi will kill that Sith. If not the Sith will try
to use an escape pod to evacuate. If there are more Siths to evacuate than the number of escape pods, only
those who have greater combat powers will use them and others will be killed by commander Jedi. Evacuated
Siths will be free.
If a Separatist Destroyer destroys a Republic Cruiser, they will take no captive and all of the crew will be
killed by the Sith commander.
If a general kills a general he will collect all of his experience. If a general kills an officer his experience will
increase by the officer’s intrinsic level.
Note that the attacker will jump to defender’s sector and coordinate to attack so the battle will take place in
defender warship’s sector and coordinate.
3.2.2 Assault
(This event is only defined for Republic Warships). This event takes place in a specific sector (sector-id will be
given). When assault takes place all Republic Cruisers will choose the closest Separatist Warship as their target
such that the target will be on their right side (Target should have a greater x-coordinate) and that target
should have a strictly smaller power output than the cruiser. So Republic aims for a hundred percent success in
the assault when selecting their targets. When two republic cruiser aims for the same target, only the one who
is closer to the target will attack and the other one won’t attack or search for a new target. Even if Republic
Cruisers attack only warships with lower power output, there is still a chance of failure since enemy Sith can convince cruiser commander or when they talk it might lower commander’s combat power so cruiser’s power output.
Assume there are 5 warships aligned in a given sector as illustrated in the figure above. When assault
begins, Halleck and Negotiator will select their targets as Malevolence since it is the nearest enemy with a lower
power output but only Negotiator will attack because Halleck is far away. There is no weak enemy on the
right of Longbeam so Longbeam won’t attack in this assault. In this assault, only Negotiator will attack (to
3.2.3 Jump To Sector
When this event happens given warship will move to given sector and coordinate. Please remind that changing
sector might change a warship’s power output.
3.2.4 Visit Corousant
Corousant is the base of the Republic and where Jedi temple is located. When a spacecraft visits corousant all
jedi crew members will have a brief talk with Jedi Grandmaster Yoda which will make their sanity 100 again.
All captives will be put in Corousant-Prison so change their state to imprisoned. A warship will return its
original sector right after this. So when next event happens warship will be present in its original sector.
3.2.5 Add Crewman
To add a crewman to a given ship crewman must be free. If any other call is made ignore it. A Jedi cannot
be added as a crewman to a Separatist ship or a Sith cannot be added as a crewman to a Republic ship, if a
call like this happens ignore and don’t do anything. Officers have no affiliations, an officer once onboard in a
republic ship may join as a crewman of separatist ship. So only condition to add an officer to any ship is that
he should be free and he should be accepted by ship. Reminder! After a crewman is onboard, he is not free
Republic and separatist ships have different accepting policies.
Republic Accepting Policy
In Republic every life matter equally so Republic ships will accept anybody if there is enough space for crewmen. (active crewman count ¡ crewman capacity of warship) If there is not enough space ignore the event and
do nothing.
Separatist Accepting Policy
In Separatist ships first, there should be enough space. (active crewman count ¡ crewman capacity of warship)
If there is not enough space ignore the event and do nothing. If there is enough space to add a new crewman,
the new crewman should increase the ship’s combat power. If after adding a new crewman, the combat power
of ship is increasing he is welcomed. If not, do not do anything. The already existing crew members will remain
as a crewmember even if they are not significant after the addition of a new member.
3.2.6 Remove Crewman
Removing is same in both republic and separatists. If member is existent as a crew member remove him and
set his state to free. if crewman is not a member of crew then ignore this action.
3.2.7 Train Officer
An officer id will be given. Training increments his intrinsic level by 1. Maximum value for intrinsic level is 10.
So if an officer has level 10 intrinsic, his intrinsic level won’t increment anymore.
3.2.8 Upgrade Warship
A warship id will be given. A keyword that will indicate which part of the warship will be incremented and the
amount will be given. Increment the proper property of that warship according to the given amount.
3.3 Output Format
You should print the final state of each crewman and warship. Warships should be printed first and they
should ordered as the warship with the higher power output(for destroyed warships power output is 0) will come
first (in case of equality the one with the lower id should come first).
If a warship is destroyed print one line in the following form:
Warship Name is destroyed by Destroyer Warship Name on ( Sector Name , Coordinate )
1. Warship Halleck is destroyed by Malevolence in (Mygeeto, 4)
If a warship is still intact print two line in the following form:
Warship Name in ( Sector Name , Coordinate )
Commander Name Power Output

Warship Malevolence in (Mygeeto, 4)
Dooku 4521
After printing warships you should print crewman final status. At first you should print generals then officers.
Generals should be ordered such that the general with higher combat power will come first (in case of equality
the one with the lower id should come first). Officers should be ordered such that the officer with the higher
intrinsic level comes first (in case of equality the one with the lower id should come first). For each crewman
print two line.
For each crewman if he is free (he is alive but actively not assigned to any warship as a crew member) print
the first line in the following form:
Crewman Type Name is free
Crewman Type can be Jedi, Sith or Officer.
• Officer Rex is free
• Jedi Windu is free
If crewman is killed during an attack by someone print the first line in the following form:
Crewman Type Name is killed by Killer Name
Crewman Type can be Jedi, Sith or Officer.
• Jedi Windu is killed by Dooku
• Officer Rex is killed by Windu
If crewman is alive and onboard or if he is captive at the warship print the first line in the following form:
Crewman Type Name is in Warship Name
Crewman Type can be Jedi, Sith or Officer.
• Sith Dooku is in Malevolence
• Jedi Skywalker is in Negotiator
If crewman is captured and imprisoned in Corousant print the first line in the following form:
Crewman Type Name is imprisoned
Crewman Type can be Sith or Officer. There is no way a jedi be imprisoned in Corousant.
• Sith Dooku is imprisoned
• Officer Rex is imprisoned
Second line for generals should contain an integer representing their final combat power. So a general should
be written in two line like in the examples below: Example:

Sith Dooku is imprisoned

Jedi Skywalker is in Negotiator
Second line for officers should contain a string (uppercase intrinsic class) and an integer (intrinsic level). So
an officer should be written in two line like in the examples below: Example:

Officer Grievous is in Malevolence

Officer Urhal is killed by Dooku
4 Submission
Submit your codes via TeachingCodes plugin before the deadline. You can submit multiple times as you proceed
with the project. Note that only your last submission will be graded. We will apply a penalty for late submissions
as explained in the next section.
5 Grading
If your code compiles and runs with no error, then you will get 10/100.
Creating class and implementing necessary fields and methods using proper object oriented design principles
will account for 10/100.
Javadoc documentation of the project will account for 10/100.
There will be different test cases. If your code can generate matching output for all test cases that will
account for 70/100. (Bonus case is not included).
Bonus There will be a large input that will test your code’s efficiency. If your code can generate matching
output in given time limit (2 min.) that will give you additional 10/100.
Late Submission If you submit within 1 day after the deadline, your grade will be calculated over 100 and
then multiplied by 0.75. If you submit within the 2nd day after the deadline, your grade will be multiplied by
0.5. We will not accept submissions after 2 days.
6 Warnings
1. This is an individual project
2. All source codes are checked automatically for similarity with other submissions. Make sure you write
and submit your own code. Any sign of cheating will be penalized.
3. Make sure you document your code with necessary inline comments and use meaningful variable names.
Do not over-comment or make your variable names unnecessarily long. This is especially important in the
main class. These will be taken into account for partial grading.
4. Please do not forget that providing the proper visibility and accessibility is important. You should not
implement everything as public. Use proper access modifiers.
5. If you want to implement a method for every child, ensure that the parent class enforces the implementation
for that method.
6. Every method must be generated in the appropriate class. Do not pass down unnecessary fields in every
7. Please direct all questions to the email address given in the first page.


There are no reviews yet.

Be the first to review “Project 2 :Star Wars Simulation”

Your email address will not be published. Required fields are marked *

Scroll to Top