Creating the Kiva Class with Optimism

How can we create the Kiva class and test its constructors?

What are the steps to implement the attributes, getters, and constructors for the Kiva class?

Answer:

To create the Kiva class and test its constructors, you need to understand class diagrams and how to read them. The Kiva class represents a robot and has instance variables such as location, carrying Pod, and successfully Dropped. The constructors should initialize the state of the Kiva object with the robot facing up, not carrying any pod, and not having successfully dropped a pod. To test the constructors, create a test class, Kiva Constructor Test, and implement the test methods test Single Argument Constructor() and test Two Argument Constructor().

Explanation:

To create the Kiva class and test its constructors, we need to understand class diagrams and how to read them. The class diagram provided in the learning materials will guide us in implementing the attributes, getters, and constructors for the Kiva class. The Kiva class represents a robot and has instance variables such as location, carrying Pod, and successfully Dropped. We will also need to import the Point class from the edu. duke package to set the location of the Kiva robot. The constructors should initialize the state of the Kiva object with the robot facing up, not carrying any pod, and not having successfully dropped a pod.

To test the constructors, we will create a test class, Kiva Constructor Test, which will contain two test methods: test Single Argument Constructor() and test Two Argument Constructor(). In the test Single Argument Constructor() method, we will create a Floor Map using the provided default Layout string and pass it to the single-argument constructor of the Kiva class. We will then check if the current Location of the Kiva object matches the expected location (2, 4). If the locations match, we will print 'test Single Argument Constructor SUCCESS' to the console; otherwise, we will print 'test Single Argument Constructor FAIL' along with the actual location.

In the test Two Argument Constructor() method, we will pass the default map and a location of (5, 6) as arguments to the two-argument constructor of the Kiva class. We will then check if the current Location of the Kiva object matches the expected location. If the locations match, we will print 'test Two Argument Constructor SUCCESS' to the console.

← Differentiating quartz cement overgrowths and quartz framework grains Create a user defined function to load maze data →