0% found this document useful (0 votes)
14 views4 pages

EECS2030A Lab 4: Vector3D Class Implementation

Uploaded by

mudafuqer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

EECS2030A Lab 4: Vector3D Class Implementation

Uploaded by

mudafuqer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EECS2030A: LAB 4 Due: Oct.

9th, 2024 - 11:59 pm


Max. Marks: 100

The purpose of this lab is to ensure that you practice

A) implementing a simple class,

B) encapsulating your data,

C) and writing unit test to test your code.

1. Setup
Please download [Link] attached to this description.
Follow these steps:
• Open eclipse. Select a directory as workspace.
• Click on File and select Import.
• Choose Existing Projects into Workspace and click Next.
• Click on Select Archive File and then Browse.
• Locate [Link] from downloads folder, select lab4.zip_expanded\Lab4 and click
Finish.
After the import, you should see two files: one named [Link] and another named
[Link].

2. Important Notes:
To practice testing, we have provided a set of incomplete test cases. Ensure that you add
enough test cases to the tester (Vector3DTester) to thoroughly test your code.

3. JavaDoc generation
The JavaDoc has already been written for you. To generate it as an HTML file for easier
navigation, follow these steps:
1. Open [Link].
2. Select Project -> Generate JavaDoc -> Next.
3. Choose the location where you want to store the documentation and click Finish.
After this process, check the specified location. You should find a file named [Link]. By
clicking on this file, you can view the documentation of the project in your browser.

Page 1 | 4
EECS2030A: LAB 4 Due: Oct. 9th, 2024 - 11:59 pm
Max. Marks: 100
4. Programming Task
This lab assumes that you are familiar with 3-dimensional vectors. If you are not familiar
with the basic mathematical operations, please review this link
([Link] which covers 2D-vectors. Note that
3D vectors are like 2D vectors, with the only difference being the addition of one more
component.
Imagine yourself as an astronaut (represented as 3D vector) on a space mission to explore a
distant galaxy. As you navigate through space, you will encounter various celestial bodies
represented as 3D vectors. Your mission is to perform vector operations to reach your
destination. Let me to guide you on how to solve the problem:
1. In the class Vector3D, define the components of the vector (i.e., x, y, z). It is necessary
to encapsulate your data since a client program, SpaceMission, will use this class later.
2. Implement the methods provided in the UML diagram below for the Vector3D class.
These methods cover the fundamental vector operations.

3. Now you should implement the SpaceMission class from scratch based on the
provided UML diagram.
SpaceMission

-currentPosition: Vector3D
+ SpaceMission(double, double, double)
+ getCurrentPosition(): Vector3D
+ distanceTo(Vector3D): double
+ refuel(double): void
+navigate(Vector3D, double, double): void

Page 2 | 4
EECS2030A: LAB 4 Due: Oct. 9th, 2024 - 11:59 pm
Max. Marks: 100
The instance variable(currentPosition) of this class shows your position (x, y, z) in
the space. Now, you have identified an interesting celestial body that you wish to
travel to. To assess its feasibility, follow the steps below:
i. First, measure the distance between your current position and the
location of the celestial body, which is represented by another vector.
For this, Implement distanceTo(Vector3D)method.
ii. To facilitate travel, there are instances where you need to refuel by
certain amounts. This process involves vector scalar multiplication.
When a vector is multiplied by a scalar, the length (magnitude) of the
vector increases proportionally to the scalar factor. To achieve this,
implement the method refuel(double) in which you must use scalar
Multiplication(double) as defined in the Vector3D class.
iii. Now, use the two methods mentioned above to implement
navigate(Vector3D, double, double). This function checks the distance
to the specified celestial body. If the distance is more than or equal to
the provided threshold, you reposition yourself to where the celestial
body is. If not, you repeatedly refuel yourself by the given refuel
amount until the distance is more than or equal to the provided
threshold. At this point, you reposition yourself.

Please note that, as the JavaDoc explains, the first input parameter
represents the position of the celestial body, the second is the
threshold, and the third is the amount by which you refuel yourself.

Please note that, as usual, the signature of the method should not change if it is given. If it is
not provided, then the signature should match what is given in the JUnit test cases.

5. Submit
You only need to submit one file named [Link] via eClass by clicking on the lab link.
This file should contain both the Vector3D and SpaceMission classes. There is no need to
submit your tester or HTML files.

6. Marking Schema
You are graded based on the correctness of your code. For each method, there will be a few
test cases to examine the correctness of the code. All test cases carry the same weight.
Please note that in all the labs, even if the test cases are provided, we will test your code with
a different set of test cases to ensure that you have tested your code completely.

Page 3 | 4
EECS2030A: LAB 4 Due: Oct. 9th, 2024 - 11:59 pm
Max. Marks: 100
Note:
▪ The program that does not compile will get zero marks
▪ No resubmissions are allowed. Therefore, please make sure you submit the correct
file within due date.
*******************************************************************************************

Page 4 | 4

Common questions

Powered by AI

Providing partially completed test cases impacts students' learning experiences positively by giving them a starting point for developing their testing skills. It encourages active learning, as students must analyze and complete these cases, fostering a deeper understanding of testing strategies and principles. This approach helps students practice creating comprehensive tests, an essential skill in software development, by engaging them in identifying potential edge cases and testing for robustness. Furthermore, it highlights the iterative nature of software testing and development, teaching students to think critically about how to ensure code correctness and reliability beyond the obvious scenarios .

Generating JavaDoc documentation in HTML format is important because it transforms code comments into a readable and navigable format, making it easier for students and developers to understand and utilize the code. For students working on the lab, viewing the documentation in a browser provides a clear reference for method descriptions, parameters, and return types, aiding them in implementing the methods correctly and ensuring they meet the requirements. The HTML format organizes the information systematically, enhancing comprehension and improving productivity by providing easy access to detailed documentation .

Strict adherence to method signatures as defined in UML diagrams and test cases is crucial because it ensures compatibility and interoperability with the provided testing framework. It is important for maintaining uniformity and fulfilling the expected interfaces, allowing test cases to work correctly without modification. Deviating from the specified signatures could lead to compilation errors or incorrect test results, impacting the assessment of correctness. Adherence also reflects professional practice, as it demonstrates an understanding of how software modules integrate and collaborate, crucial for maintaining and scaling larger projects .

The navigate method integrates vector operations by first calculating the distance from the current position to a target celestial body using the distanceTo method. If the distance is greater than or equal to a threshold specified by the second parameter, the method sets the current position vector to the target position. If the distance is less than the threshold, the method repeatedly uses the refuel method to perform scalar multiplication on the vector until the distance or threshold condition is satisfied, effectively navigating through space by updating the vector's position to the target location. This method demonstrates how various vector operations can be combined to simulate navigation in space .

Scalar multiplication in the refuel method is used to increase the magnitude of a vector by a specific factor, which represents adding fuel or energy to enhance travel capability. When a vector is multiplied by a scalar, each component of the vector is multiplied by this scalar, thus scaling the vector proportionally. In the SpaceMission class, refuel utilizes this operation to simulate the action of adding enough fuel to possibly reach a distant celestial body, as it modifies the vector representing the spacecraft's position .

Implementing tasks involving both the Vector3D and SpaceMission classes offers significant educational benefits by providing students with a comprehensive understanding of how multiple classes can interact to solve complex problems. It allows students to practice object-oriented design principles such as encapsulation, inheritance, and method abstraction in a contextual setting, enhancing their problem-solving skills. By working with interrelated classes, students learn to develop modular code that can be reused and integrated, fostering an understanding of real-world application development. This task challenges them to synthesize discrete elements into a cohesive program, deepening their grasp of both theoretical concepts and practical applications .

The SpaceMission class implements data encapsulation by using the currentPosition instance variable, which is a Vector3D object, to manage the spatial position privately. This variable is accessed and modified through defined methods such as getCurrentPosition, thereby preventing direct manipulation and protecting the integrity of the position data. This approach enhances code usability by providing a clear interface for interaction while securing the internal representation. It also improves safety by minimizing potential errors from direct attribute modifications, ensuring that only intended operational logic influences the spacecraft's position .

Encapsulation in the Vector3D class is crucial because it keeps the internal data of the vector (x, y, z components) private, ensuring that they can only be accessed and modified through well-defined methods. This prevents unintended interference and maintains data integrity. By encapsulating data in this manner, the class can be safely used by a client program, such as SpaceMission, without exposing the underlying representation of the vector, thereby supporting the object-oriented principle of information hiding. This is outlined in the document where it discusses the importance of data encapsulation for client program usage .

UML diagrams are significant as they provide a clear blueprint for the structure and relationships within the code. In this lab, the UML diagrams outline the methods and attributes of the Vector3D and SpaceMission classes, guiding students on how to implement and organize their code. By following UML diagrams, students gain insight into the intended design of the software, including method signatures and interactions, which helps maintain consistency and ensures that the implemented classes meet the defined specifications. This approach facilitates a better understanding of object relationships and improves coding practices by encouraging adherence to pre-defined structures .

Thorough unit testing is critical in the lab to verify the correctness of the implemented methods and ensure that they perform as expected under various conditions. The document stresses the importance of comprehensive testing by requiring students to add sufficient test cases to the provided incomplete set in Vector3DTester. To ensure completeness, students must design test cases that cover all possible scenarios, including edge cases, and validate the logic of vector operations like distance calculation and refueling. The emphasis on testing with different cases, beyond the provided examples, highlights the lab's goal of practicing robust test coverage .

You might also like