Last active
October 26, 2015 18:20
-
-
Save AnnaBoro/955d9cb54e975ddba682 to your computer and use it in GitHub Desktop.
lesson4-Frame15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson4; | |
public class Car { | |
private String name = "ref3"; | |
private String ownerName; | |
private String vehicleCategory; | |
private int capacity; | |
private int maxSpeed; | |
private boolean isFull; | |
private Driver driver; | |
public Car() { | |
} | |
public void setDriver(Driver driver) { | |
this.driver = driver; | |
} | |
public boolean canDrive() { | |
if(driver.getDrivingExperience() > 5) { | |
return true; | |
} | |
return false; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
if (name != null) { | |
this.name = name; | |
} | |
} | |
public String getOwnerName() { | |
return ownerName; | |
} | |
public void setOwnerName(String ownerName) { | |
if (ownerName != null) { | |
this.ownerName = ownerName; | |
} | |
} | |
public String getVehicleCategory() { | |
return vehicleCategory; | |
} | |
public void setVehicleCategory(String vehicleCategory) { | |
if (vehicleCategory != null) { | |
this.vehicleCategory = vehicleCategory; | |
} | |
} | |
public int getCapacity() { | |
return capacity; | |
} | |
public void setCapacity(int capacity) { | |
if (capacity > 0) { | |
this.capacity = capacity; | |
} | |
else { | |
this.capacity = 0; | |
} | |
} | |
public int getMaxSpeed() { | |
return maxSpeed; | |
} | |
public void setMaxSpeed(int maxSpeed) { | |
if (maxSpeed > 130) { | |
maxSpeed = 130; | |
} | |
else { | |
this.maxSpeed = maxSpeed; | |
} | |
} | |
public boolean isFull() { | |
return isFull; | |
} | |
public void setFull(boolean isFull) { | |
this.isFull = isFull; | |
} | |
public Car(Driver driver) { | |
this.driver = driver; | |
} | |
public Driver getDriver() { | |
return driver; | |
} | |
public void printRefName() { | |
System.out.println(name + " " + driver.getName()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson4; | |
public class Cargo { | |
private String name = "ref2"; | |
private int weight; | |
private int price; | |
private boolean isDanger; | |
private boolean hasDocument; | |
private Car car; | |
public Cargo() { | |
} | |
public Cargo(Car car) { | |
this.car = car; | |
} | |
public boolean transportCargo() { | |
if(car.getCapacity() > weight) { | |
return false; | |
} | |
return true; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
if (name != null) { | |
this.name = name; | |
} | |
} | |
public int getWeight() { | |
return weight; | |
} | |
public void setWeight(int weight) { | |
if (weight > 0) { | |
this.weight = weight; | |
} | |
} | |
public int getPrice() { | |
return price; | |
} | |
public void setPrice(int price) { | |
if (price >= 0) { | |
this.price = price; | |
} | |
} | |
public boolean isDanger() { | |
return isDanger; | |
} | |
public void setDanger(boolean isDanger) { | |
this.isDanger = isDanger; | |
} | |
public boolean isHasDocument() { | |
return hasDocument; | |
} | |
public void setHasDocument(boolean hasDocument) { | |
this.hasDocument = hasDocument; | |
} | |
public Car getCar() { | |
return car; | |
} | |
public void setCar(Car car) { | |
this.car = car; | |
} | |
public void printRefName() { | |
System.out.println(name + " " + car.getName()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson4; | |
public class Driver { | |
private String name = "ref1"; | |
private int age; | |
private int drivingExperience; | |
private boolean hasDriverLicenseNecessaryCategory; | |
private Cargo cargo; | |
public Driver() { | |
} | |
public Driver(Cargo cargo) { | |
this.cargo = cargo; | |
} | |
public boolean agreeToCarry() { | |
if(cargo.isDanger()) { | |
return false; | |
} | |
return true; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
if (name != null) { | |
this.name = name; | |
} | |
} | |
public int getAge() { | |
return age; | |
} | |
public void setAge(int age) { | |
if (age >= 18) { | |
this.age = age; | |
} | |
else { | |
this.age = 0; | |
} | |
} | |
public int getDrivingExperience() { | |
return drivingExperience; | |
} | |
public void setDrivingExperience(int drivingExperience) { | |
if (drivingExperience > 0) { | |
this.drivingExperience = drivingExperience; | |
} | |
else { | |
this.drivingExperience = 0; | |
} | |
} | |
public boolean isHasDriverLicenseNecessaryCategory() { | |
return hasDriverLicenseNecessaryCategory; | |
} | |
public void setHasDriverLicenseNecessaryCategory(boolean hasDriverLicenseNecessaryCategory) { | |
this.hasDriverLicenseNecessaryCategory = hasDriverLicenseNecessaryCategory; | |
} | |
public Cargo getCargo() { | |
return cargo; | |
} | |
public void setCargo(Cargo cargo) { | |
this.cargo = cargo; | |
} | |
public void printRefName() { | |
System.out.println(name + " " + cargo.getName()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lesson4; | |
public class Transportation { | |
public static void main(String[] args) { | |
Cargo cargo = new Cargo(); | |
Driver driver = new Driver(); | |
Car car = new Car(); | |
driver.setCargo(cargo); | |
car.setDriver(driver); | |
cargo.setCar(car); | |
driver.printRefName(); | |
cargo.printRefName(); | |
car.printRefName(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment