Doctor CS and the AIs

Introduction

(If this comic book-esque backstory is unimportant to you, simply ignore it and go straight to the solution description.)

The world-famous hero, the Doctor CS, was checking his numerous emails one day when suddenly he gets a call from his sidekick Burdell Boy warning him of a surprise attack from his arch nemesis Dr. Chipotle. He needs your help using his programming superpowers to create AIs to stop the villain’s highly destructive guac cannon from destroying Georgia Tech before it’s too late! While you’re there, you might as well get some revenge on Dr. Chipotle as well. You know, for the good of humanity.

Problem Description

Write five classes, AI, RandomAI, RogueAI, DoctorCS, and Coordinates to help our hero pull off his perilous plan. The AI class and by extension, its subclasses (RandomAI and RogueAI), have some important information we need in order to get revenge on our sworn enemy, including the location of Dr. Chipotle’s secret lair. Once you get this information, you can change the cannon to attack Dr. Chipotle’s lair instead of Doctor CS’s HQ. However, Dr. Chipotle anticipated the counterattack and has installed a security measure into his cannons: a self-destruct sequence virus. Should the virus activate, any AI trying to stop the cannon will be destroyed, and the cannon will fire anyways at its original target (and Georgia Tech gets guac’ed). If it is possible without triggering the self destruct, you should change the cannon target to Dr. Chipotle’s lair. If it is not possible, then Dr. Chipotle will have succeeded in his plan to destroy Georgia Tech.

TL;DR (Too Long; Didn’t Read) Dr. Chipotle is trying to destroy Georgia Tech, and you have to make some classes that use the features of object-oriented programming to stop him.

Solution Description

Complete the AI, RandomAI, RogueAI, DoctorCS, and Coordinates classes following the instructions below. Note: When creating the specified getter and setter methods for each class, use the naming convention taught in class, e.g. getFirewallProtection() and setSecretIdentity().

For all of the classes you write, Don’t add any unneeded fields.

Don’t forget to answer the Analysis questions.

Coordinates.java

This class should be concrete.

Fields

This class has the following private fields, and associated getter methods:

Constructor

This class has the following constructor:

Methods

This class has the following public methods:

AI.java

The foundation for any AI Doctor CS creates. This class should be made abstract.

Fields

This class has the following private fields, and associated getter methods for them:

Constructor

This class will have the following constructor:

Methods

This class will have the following methods alongside the getters specified in the Fields section:

RandomAI.java

RandomAI extends AI but isn’t very smart. When you tell it to swapCannonTarget(), there’s a 50% chance that it will, and a 50% that it won’t. If it doesn’t swap the target, there’s a 50% chance that it will self destruct. This class should be concrete.

Fields

This class has the following private static final field:

Constructor

This class will have the following constructor:

Methods

This class will have the following methods:

RogueAI.java

RogueAI extends AI and can detect firewalls in the guac cannon’s software as well as alert levels. RogueAI can lower the firewalls, but that increases the alert level as well. If the alert level exceeds the maximum alert level, then the self-destruct virus will be activated, and that instance of RogueAI will be destroyed. This class should be concrete.

Fields

This class has the following private fields and associated getter methods for them:

Be sure to make the instance fields private so that only your methods within the class have access to them!

Constructor

This class will have the following constructors:

Use constructor delegation! For this homework, make constructors with fewer arguments delegate to constructors with more arguments.

Methods

This class has the following methods alongside the getters specified in the Fields section:

DoctorCS.java

Our hero, Doctor CS, gets his own class. He will have an AI at his disposal to stop Dr. Guacamole’s evil plan, and has a secret identity that no person, aside from himself, knows about. This class should be concrete.

Fields

This class has the following private fields, and associated getter and setter methods for them unless otherwise specified:

Constructor

This class has the following constructor:

Methods

This class has the following public methods:

Analysis

DoctorCS’s saveTheDay method forces you to use instanceof. Answer the following questions as a comment at the top of DoctorCS.java:

  1. Why is this not good style?
  2. What changes could we make to AI and it’s subclasses to avoid using instanceof?

Use no more than 100 words in total to answer both questions. Word counter

Grading

General Points (35 points)

AI.java (15 points)

RandomAI.java (4 points)

RogueAI.java (16 points)

DoctorCS.java (17 points)

Coordinates.java (13 points)

Analysis (10 bonus points)

Running and Testing

CrimeSimulator.java has been provided for you. It creates an instance of a DoctorCS, RogueAI, and Coordinates and invokes various methods on each. You can run the main method to test the functionality of your code. The tester may not cover all cases described above, so be sure to write your own code to test your classes and methods.

Here is the expected output from CrimeSimulator:

Robert Paulson aka DoctorCS with JLAID: 13310001
Dr. Chipotle’s guacamole cannon is currently pointed at latitude: 13.31, longitude: 23.16, and is at alert level 0 with firewall protection 10.
Dr. Chipotle’s guacamole cannon is currently pointed at latitude: 50.00, longitude: 25.50, and is at alert level 5 with firewall protection 0.
Doctor CS has saved the day!
false

Tips and Considerations

Please start as soon as possible! The earlier you start this assignment, the more time you will have to think and ask questions. If anything seems confusing, read through the entire description and instructions again. As always, feel free to contact your TAs, post on Piazza, or come in for office hours. In addition, here are some tips specific to this homework:

Allowed imports

You are allowed to import the following classes and only the following classes:

Javadocs

Checkstyle

You must run checkstyle on your code to check for violations. For each violation the tool finds, you will lose one point on your total grade for this assignment.

For this homework, the checkstyle cap is 50, meaning you can lose up to 50 points on this assignment due to style errors. As the semester goes on, this cap will increase with each homework and will eventually go away. Run checkstyle early, and get in the habit of writing style compliant code the first time. Don’t wait until 5 minutes before the deadline to find out that you have 100+ violations.

Collaboration

When completing homeworks for CS1331 you may talk with other students about:

You may not discuss, show, or share by other means the specifics of your code, including screenshots, file sharing, or showing someone else the code on your computer, or use code shared by others.

Examples of approved/disapproved collaboration:

In addition to the above rules, note that it is not allowed to upload your code to any sort of public repository. This could be considered an Honor Code violation, even if it is after the homework is due.

Submission

Submit your DoctorCS.java, AI.java, RandomAI.java, RogueAI.java, and Coordinates.java files as attachments to the hw4 assignment on Canvas. Be sure to check Piazza for clarifications and updates before submitting. You can submit as many times as you want, so feel free to submit as you make substantial progress on the homework. We only grade your last submission, meaning we will ignore any previous submissions. Submit every file every time you resubmit.

As always, late submissions will not be accepted and non-compiling code will be given a score of 0. For this reason, we recommend submitting early and then confirming that you submitted ALL of the necessary files by re-downloading your file(s) and compiling/running them.

Good luck, and have fun!