$20
Problem Description
Since your bizarre time traveling incident from a few weeks ago, you’ve successfully launched your own forum site, helped the owner of a local puppy shelter modernize their business, explored the curious properties of Conway’s Game of Life, and have created a dueling simulator for Professor Dumbledore at Hogwarts. Needless to say, things have been looking up for being trapped in 1998! However, much to your dismay your forum site has had very little activity; apparently no one else has experienced similar time traveling incidents.
However, today that is about to change! Instead of waking up in your bed this morning, you wake up in a futuristic cell, and in a much more comfortable bed. You are greeted by a bizarre humanoid creature with yellow-green, scaly skin. It approaches you, and says, “Good morning, human. I apologize for the previous mishap in our time travel device; it has been acting up due to recent events. My name is Silik, and I am the leader of the Suliban Cabal. You are currently hundreds of light-years away from Earth on my ship, and it is the Earth year 2745. Species around the universe are currently engaged in a Temporal Cold War, which has caused the timeline to become seriously disrupted. My men have taken heavy damage in an attempt to fix it, and we need your help to restore the timeline. We currently lack sufficient technical manpower to restore our database on Starfleet and the history of your species. Because of your great technical ability, you have been selected to create the infrastructure that will restore it. You will start with data representations of humans, androids, and Vulcans; we believe events related to these three species particularly disrupted the timeline. Once your work is complete, we will send you back to your own time so you can resume your studies, but only if you are successful. We have much Java documentation to guide your work, and we will provide an IDE that you are comfortable with. Remember, the timeline depends on your success, so we can’t afford any mishaps. Good luck!”
Solution Description
For this assignment, you will be dealing with 3 concrete classes, an abstract class, an enumeration, and 2 interfaces.
The following files are provided to you for your reference. You will have to implement methods declared in them, but you will not have to modify any code in the files themselves:
• Alien.java
• Logic.java
• Rank.java
In these files, the following methods have been provided:
Alien.java
• This file contains the Alien abstract class.
• It contains a singular method, String getHomePlanet();
– This method will need to be implemented in Vulcan.java, which extends it.
Logic.java
• This file contains the Logic interface.
• It contains a singular method, boolean isPrime(int num);
– This method will need to be implemented in both Vulcan.java and Android.java.
– The Vulcan species is well-known for being calculating and logical, rather than emotional and instinctive like say, humans or Andorians, which is why they implement this interface. Similarly, androids are part human, part machine, so internally they use much precise logic to function!
– Since both Vulcans and androids are “calculating” and logical, it would make sense that they would need mathematical capabilities to perform their decisions.
– See the file itself for implementation details.
Rank.java
• This file contains the Rank enumeration type.
• It contains a list of Rank enums to be used in the next 4 listed files. See details below for their specific use cases.
You will need to make changes to the following files, and you will be submitting them to Gradescope:
• Officer.java
• Human.java
• Vulcan.java
• Android.java
Officer.java
• This file contains the Officer interface.
• It contains 2 abstract methods, String getName(); and Rank getRank();.
– These methods will need to be implemented in Vulcan.java, Android.java, and Human.java. Since the Cabal’s database only deals with members of these entities that are part of Starfleet, we know that all instances of them will be Starfleet officers, which is why this interface is used. – See the file itself for implementation details.
• Additionally, there is one method in this file that you have to implement: default String rankString();
– See the file itself for implementation details.
• Lastly, there is an implemented static String method provided to you, private String capitalizeEachWord(String rank);, that will be used in the implementation of default String rankString();. No need to modify this method.
Human.java
• This file contains the Human concrete class.
• This class will implement the Officer interface. See Officer.java for its requirements.
– For any method overridden from this interface make sure to use the @Override annotation directly above each method header.
• It will have 2 instance variables, String name and Rank rank
– name should never be able to be changed once initialized in the constructor. What keyword would allow us to do this?
– rank is allowed to be modified after initialization
• It should also have exactly one constructor, which takes in String name and int rank. It should assign String name accordingly.
– However, we must get the Rank enum value corresponding to int rank. A rank of 0 corresponds to Rank.ENSIGN, rank of 1 to Rank.LIEUTENANT, and so on. Note that we can only obtain a valid rank if 0 <= rank <= 5.
– So, if int rank is negative or greater than 5, initialize Rank rank to null. Otherwise, obtain the corresponding enum rank using Rank.values(), and set Rank rank equal to it.
• This class will also implement the overridden methods public String toString() and public boolean equals(Object other) from java.lang.Object
– For any method overridden from java.lang.Object make sure to use the @Override annotation directly above each method header.
– See the file for implementation details.
Vulcan.java
• This file contains the Vulcan concrete class.
• This class will implement the Officer interface. See Officer.java for its requirements.
– For any method overridden from this interface make sure to use the @Override annotation directly above each method header.
• This class will also implement the Logic interface.
– For any method overridden from this interface make sure to use the @Override annotation directly above each method header.
– See Vulcan.java for implementation details.
• This class will also extend the Alien abstract class. See Alien.java for its requirements. – Note that the home planet of a Vulcan is Vulcan!
– For any method overridden from this abstract class make sure to use the @Override annotation directly above each method header.
• It will have 2 instance variables, String name and Rank rank
– name should never be able to be changed once initialized in the constructor. What keyword would allow us to do this?
– rank is allowed to be modified after initialization
• It should also have exactly one constructor, which takes in String name and int rank. It should assign String name accordingly.
– However, we must get the Rank enum value corresponding to int rank. A rank of 0 corresponds to Rank.ENSIGN, rank of 1 to Rank.LIEUTENANT, and so on. Note that we can only obtain a valid rank if 0 <= rank <= 5.
– So, if int rank is negative or greater than 5, initialize Rank rank to null. Otherwise, obtain the corresponding enum rank using Rank.values(), and set Rank rank equal to it.
• You should create an additional overloaded method boolean isPrime(int num1, int num2); – This method overloads the method boolean isPrime(int num); from the Logic interface. – See Vulcan.java for its implementation details.
• This class will also implement the overridden methods public String toString() and public boolean equals(Object other) from java.lang.Object
– For any method overridden from java.lang.Object make sure to use the @Override annotation directly above each method header.
– See the file for implementation details.
Android.java
• This file contains the Android concrete class.
• This class will extend the Human concrete class. However, no methods will be overridden from that class.
• This class will also implement the Logic interface.
– For any method overridden from this interface make sure to use the @Override annotation directly above each method header.
– See Android.java for implementation details.
• This class will not have any instance variables! Instead, it will pass String name and int rank to the constructor of its superclass, Human
– Implement a constructor that takes in String name and int rank. This constructor should call the superclass constructor in Human, which takes in the same parameters. This can be accomplishes using the super keyword.
– It should have a second, no-arg constructor that uses constructor chaining with the this keyword to call the other constructor with parameters "Data" and 2.
• You should create an additional overloaded method boolean isPrime(int num1, int num2, int num3);
– This method overloads the method boolean isPrime(int num); from the Logic interface. – See Android.java for its implementation details.
• This class will also implement the overridden method public String toString().
– For any method overridden from java.lang.Object make sure to use the @Override annotation directly above each method header.
– See the file for implementation details.
Important: Make sure each constructor that takes in String name and int rank takes them in exactly in that order!
Testing your code:
We have provided a driver class that you can use to test your code:
• Enterprise.java
You should create your own tests in the main method! Here is what the expected output of the main method we have provided is:
Captain Kirk
Captain Picard
Admiral Forrest
Android Lieutenant Commander Data
Android Lieutenant Commander Data
Commander Spock from Vulcan
Commander T'Pol from Vulcan
Captain Picard Unranked Daniels
false true false true
false true false false