What is the finished code in Java? I posted this earlier and it was wrong.... tr
ID: 3730079 • Letter: W
Question
What is the finished code in Java? I posted this earlier and it was wrong.... try and use as basic terms as possible to.
package labQuadrotors;
public class Quadrotor
{
private int x;
private int y;
private int z;
public Quadrotor(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
public int getX()
{
return x;
}
public void setX(int x)
{
this.x = x;
}
public int getY()
{
return y;
}
public void setY(int y)
{
this.y = y;
}
public int getZ()
{
return z;
}
public void setZ(int z)
{
this.z = z;
}
@Override
public String toString()
{
return "QR:" + x + "/" + y + "/" + z;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + x;
result = prime * result + y;
result = prime * result + z;
return result;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof Quadrotor))
return false;
Quadrotor other = (Quadrotor) obj;
if (x == other.x && y == other.y && z == other.z)
return true;
return false;
}
}
What is a Quadrotor? Check out this video Download Quadrotor.java In the same directory create a file called QuadrotorApp. It includes the main method In main do the following: Create a List of Quadrotors and initialize it with 6quadrotors like this: ListExplanation / Answer
here is your class : --------->>>>>>>>>
import java.util.*;
public class QuadrotoApp{
private static void changeOrientation(List<Quadrotor> rotors){
int temp;
for(int i = 0;i<rotors.size();i++){
temp = rotors.get(i).getX();
rotors.get(i).setX(rotors.get(i).getY());
rotors.get(i).setY(temp);
}
}
public static void main(String[] args) {
List<Quadrotor> rotors = new ArrayList<>(Arrays.asList(new Quadrotor(2,4,2),new Quadrotor(3,4,4),
new Quadrotor(4,4,6),new Quadrotor(5,4,2),new Quadrotor(6,4,4),new Quadrotor(7,4,6)));
//first uncoment this and comment above line
/*List<Quadrotor> rotors = Arrays.asList(new Quadrotor(2,4,2),new Quadrotor(3,4,4),
new Quadrotor(4,4,6),new Quadrotor(5,4,2),new Quadrotor(6,4,4),new Quadrotor(7,4,6));*/
System.out.println(rotors);
changeOrientation(rotors);
System.out.println(rotors);
Quadrotor searchItem = new Quadrotor(4,6,4);
if(rotors.contains(searchItem)){
System.out.println("rotors does contains "+searchItem);
}
System.out.println(" Number of rotors "+rotors.size()+" ");
try{
rotors.remove(searchItem);
}catch(Exception e){
System.out.println(" You are using only list not ArrayList");
}
System.out.println(rotors);
rotors.remove(0);
System.out.println(rotors);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.