Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Creating a Drone - JAVA • Create a VirtualDrone class • Constructors: VirtualDro

ID: 3724813 • Letter: C

Question

Creating a Drone - JAVA

• Create a VirtualDrone class

• Constructors: VirtualDrone(int) where the parameter is the cost in dollars.• Depending on the cost assign some values to your Drone properties

• A default constructor:

• VirtualDrone()

• Define private Properties (bCanFly, bCanJump, iBatteryCapacity, and methods to query them using this.property)

• Method: bMoveBy(x,y,z) • Should consume battery • Should refuse to go up if cannot fly

• Method: iGetBatteryCharge()

• Method int[] ipGetGPS(); // returns an array of current x,y,z coordinates

Explanation / Answer

public class VirtualDrone { private int cost; private boolean canFly; private boolean canJump; private int batteryCapacity; private int x, y, z; public VirtualDrone(int cost) { this.cost = cost; this.x = 0; this.y = 0; this.z = 0; this.canFly = true; this.canJump = true; this.batteryCapacity = 100; } public int getCost() { return this.cost; } public void setCost(int cost) { this.cost = cost; } public boolean isCanFly() { return this.canFly; } public void setCanFly(boolean canFly) { this.canFly = canFly; } public boolean isCanJump() { return this.canJump; } public void setCanJump(boolean canJump) { this.canJump = canJump; } public int getBatteryCapacity() { return this.batteryCapacity; } public void setBatteryCapacity(int batteryCapacity) { this.batteryCapacity = batteryCapacity; } public int[] ipGetGPS() { return new int[] {x, y, z}; } public boolean bMoveBy(int x, int y, int z) { if(canFly) { this.x += x; this.y += y; this.z += z; this.batteryCapacity -= 5; if(batteryCapacity < 0) { batteryCapacity = 0; canFly = false; } } return canFly; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote