question archive public class Vehicle { public String manfacname; public int cylinders; public Person owner;   public Vehicle() {   }   public Vehicle(String str, int num) { manfacname = str; cylinders = num; }   public void drivedBy(String name) { owner = new Person(); owner

public class Vehicle { public String manfacname; public int cylinders; public Person owner;   public Vehicle() {   }   public Vehicle(String str, int num) { manfacname = str; cylinders = num; }   public void drivedBy(String name) { owner = new Person(); owner

Subject:Computer SciencePrice:2.89 Bought3

public class Vehicle {

public String manfacname;

public int cylinders;

public Person owner;

 

public Vehicle()

{

 

}

 

public Vehicle(String str, int num)

{

manfacname = str;

cylinders = num;

}

 

public void drivedBy(String name)

{

owner = new Person();

owner.setName(name);

}

 

}

 

 

public class Person {

String name;

 

public Person() {

name = "No name yet";

}

 

public Person(String initialName) {

name = initialName;

}

 

public void setName(String newName) {

name = newName;

}

 

public String getName() {

return name;

}

 

public void writeOutput() {

System.out.println("Name: " + name);

}

 

public boolean hasSameName(Person otherPerson) {

return this.name.equalsIgnoreCase(otherPerson.name);

}

}

 

 

public class Truck extends Vehicle{

public double loadcapacity;

public double towingcapacity;

 

public Truck(double load, double town)

{

loadcapacity = load;

towingcapacity = town;

}

 

public String checkLoad()

{

if (loadcapacity > 1000)

{

return "Too much load";

}

else

return "You can carry";

}

 

public boolean move()

{

if (checkLoad().equals("Too much load"))

{

return false;

}

else

return true;

 

}

 

}

 

 

public class Driver {

Vehicle veh;

Truck tr;

 

public Driver(String name, double load, double tow)

{

tr = new Truck(load, tow);

veh = new Vehicle();

veh.drivedBy(name);

tr.checkLoad();

if (tr.move())

System.out.println(veh.owner.getName() + " can drive the truck");

else

System.out.println(veh.owner.getName() + " can't drive the truck");}public static void main(String args[]) {new Driver("Ali", 800, 800);}}

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

The problem with this is the values in both memory cells would not be able to interchange according to the given steps because when content of cell 2 is moved to cell 3. The initial value of cell 3 would be replaced by the content of cell 2, so in step 2 the same content would be moved in cell 2 which is already placed in cell 2. So Interchanging not be possible in this way.

In order to interchange 2 cell contents we can use another temporary cell (cell number 4) and these steps should be followed in order to get best results.

  • Step 1: Move the content of cell number 2 to cell number 4.
  • Step 2: Move the content of cell number 3 to cell number 2.
  • Step 3: Move the content of cell number 4 to cell number 3.