Скачиваний:
15
Добавлен:
01.05.2014
Размер:
4.52 Кб
Скачать
/*
* Human.java
*
* Created on April 20, 2007, 3:01 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package ic.core;

import ic.core.U;

/**
*
* @author adm
*/
public class Human {
Furniture f = null;
Computer pc = null;
String name = null;
Budget b = null;
IProvider ip = null;
IConnection ic = null;

public IProvider getIProvider () {
return this.ip;
}

public IConnection getIConnection() {
return this.ic;
}

public boolean buyIConnection (IProvider ipr, IConnection ico) {
if(this.ic != null || this.ip != null)
return true;
if(this.b.cash() < ico.getMonthFee())
return false;
this.ip=ipr;
this.ic=ico;
return true;
}

/** Creates a new instance of Human */
public Human(String name, float cash) {
this.name = name;
this.b = new Budget(cash);
U.log("Human was born. His name is: "+name+" Cash flow: "+cash+"\n");
}

public String getName() {
return this.name;
}

public Budget getBudget() {
return b;
}

public Computer getPC() {
return pc;
}

public Furniture getFurniture() {
return f;
}

public boolean hasComputer() {
if(pc == null)
return false;
else
return true;

}

public boolean hasFurniture() {
if(f == null)
return false;
else
return true;

}

public boolean buyComputer(Computer.Productivity p, ComputerSalesCompany comp, String computer) {
boolean bought = comp.saleComputer(this.b, computer);
if(bought) {
this.pc = new Computer(p);
return true;
}
else return false;
}

public boolean buyComputer(Computer c) {
if (this.pc != null)
return true;
if (c.getPrice() < b.cash()) {
this.pc = new Computer(c.getProductivity());
pc.setName(c.getName());
pc.setPrice(c.getPrice());
pc.setSeller(c.getSeller());
b.decreaseCash(pc.getPrice());

return true;
}
else {
return false;
}
}

public boolean buyFurniture(Furniture c) {
if (this.f != null)
return true;
if (c.getPrice() < b.cash()) {
this.f = new Furniture(c.getBeauty());
f.setName(c.getName());
f.setPrice(c.getPrice());
f.setSeller(c.getSeller());
b.decreaseCash(f.getPrice());

return true;
}
else {
return false;
}
}

public boolean buyFurniture (Furniture.Beauty b, FurnitureSalesCompany comp, String furniture) {
boolean bought = comp.saleFurniture(this.b, furniture);
if(bought) {
this.f = new Furniture(b);
return true;
}
else return false;
}

public boolean buySoftwarePackage (SoftwarePackage sp) {
if (pc!=null & pc.getSoftwarePackage() == null) {
pc.setSoftwarePackage(sp);
b.decreaseCash(sp.getPrice());
return true;
}
return false;
}

public boolean buySoftwarePackage(float packagePrice, String osName, String officeName) {
if(b.cash() < packagePrice)
return false;
if(pc==null)
return false;
SoftwarePackage s = new SoftwarePackage(osName, officeName, packagePrice);
pc.setSoftwarePackage(s);
return true;
}

public boolean installSoftwarePackage() {
//SoftwarePackage.InstallationWay iway = SoftwarePackage.InstallationWay.myself;
if(this.pc == null )
return false;
if(this.pc.getSoftwarePackage() == null)
return false;
//this.pc.getSoftwarePackage().startInstallation(iway);
return true;
}

public boolean callSpecialist(ComputerSpecialist cs) {
if(cs.install(this.pc.getSoftwarePackage(), b))
return true;
else
return false;
}



}
Соседние файлы в папке core