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
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);}}
Purchased 3 times