// This constructor is called for new children public Human(Human progenitor) { mode = LifeStage.EARNING; parent = progenitor; myId = nextAgentNum++; producedCommodity = Model.instance().generateMake(this); residentCommunity = parent.residentCommunity; age = 0; money = 100; children = new ArrayList<Human>(); minThreshold = new double[Commodity.NUM_COMM]; // Between 0 and 5 commoditiesHeld = new double[Commodity.NUM_COMM]; timesTraded = 0; for (int i = 0; i < Commodity.NUM_COMM; i++) { minThreshold[i] = Model.instance().generateNeedCommodityThreshold(); while (minThreshold[i] < Commodity.getCommNum(i).getAmtCons()) { minThreshold[i] = Model.instance().generateNeedCommodityThreshold(); } Commodity.getCommNum(i).incNeed(minThreshold[i]); expPrice[i] = Model.instance().generateExpPrice(); commoditiesHeld[i] = 0; } allNeeds = 0; for (int i = 0; i < Commodity.NUM_COMM; i++) { allNeeds += minThreshold[i]; } amountProduced = Model.instance().generateAmountProduced(); Commodity.getCommNum(producedCommodity).incMakerNum(amountProduced); parent.children.add(this); Model.instance().addToActors(this); Model.instance().addToCommunity(residentCommunity, this); }
@Test public void shouldReturnFalseOnComparingWithACommodityOfDifferntNameAndPrice() { Commodity commodity1 = new Commodity("bottle of perfume", 18.99); Commodity commodity2 = new Commodity("book", 12.49); assertEquals(false, commodity1.compareWithCommodity(commodity2)); }
@Test public void shouldReturnTrueOnComparingWithACommodityOfSameNameAndPrice() { Commodity commodity1 = new Commodity("bottle of perfume", 18.99); Commodity commodity2 = new Commodity("bottle of perfume", 18.99); assertEquals(true, commodity1.compareWithCommodity(commodity2)); }
@Test public void testDelete() throws Exception { commodityViewDAO.create(commodityView); List<CommodityView> c = commodityViewDAO.getByIdCommodity(commodity.getId()); for (CommodityView test : c) commodityViewDAO.delete(test.getId()); assertThat( "Expected empty List ", commodityViewDAO.getByIdCommodity(commodity.getId()).isEmpty(), is(true)); }
@Override public boolean geographicallyIdenticalTo(Route t) { if (this.taskSet.size() != t.taskSet.size()) return false; int tsize = taskSet.size(); Vector<Task> t2 = t.taskSet; for (int i = 0; i < tsize; i++) { Commodity c1 = taskSet.get(i).cmdt, c2 = t2.get(i).cmdt; if (!c1.geographicallyIdenticalTo(c2)) return false; } return true; }
// Constructors & destructors // -------------------------------------------------------------------------- // This constructor is called for initial agents public Human() { myId = nextAgentNum++; mode = LifeStage.EARNING; /*if (myId == 0 || myId == 1) { producedCommodity = myId; } else {*/ producedCommodity = Model.instance().generateMake(this); // } residentCommunity = Model.instance().generateCommunity(this); age = 0; // Model.instance().generateAge(); money = Model.MONEY; children = new ArrayList<Human>(); minThreshold = new double[Commodity.NUM_COMM]; // Between 0 and 5 commoditiesHeld = new double[Commodity.NUM_COMM]; expPrice = new double[Commodity.NUM_COMM]; chokeQuant = new double[Commodity.NUM_COMM]; demandSlope = new double[Commodity.NUM_COMM]; budget = new double[Commodity.NUM_COMM]; // New trade variables alpha = new double[Commodity.NUM_COMM]; beta = new double[Commodity.NUM_COMM]; goodUtils = new double[Commodity.NUM_COMM]; utilsDollar = new double[Commodity.NUM_COMM]; budgetExp = new double[Commodity.NUM_COMM]; timesTraded = 0; for (int i = 0; i < Commodity.NUM_COMM; i++) { minThreshold[i] = Commodity.getCommNum(i) .getAmtCons(); // Model.instance().generateNeedCommodityThreshold(); /* while( minThreshold[i]< Commodity.getCommNum(i).getAmtCons()) { minThreshold[i]=Model.instance().generateNeedCommodityThreshold(); }*/ Commodity.getCommNum(i).incNeed(minThreshold[i]); expPrice[i] = Model.instance().generateExpPrice(); chokeQuant[i] = Model.instance().generateChokeQuant(); demandSlope[i] = Model.instance().generateDemandSlope(); alpha[i] = Model.instance().generateAlpha(); beta[i] = Model.instance().generateBeta(); commoditiesHeld[i] = 0; } allNeeds = 0; for (int i = 0; i < Commodity.NUM_COMM; i++) { allNeeds += minThreshold[i]; } amountProduced = Model.instance().generateAmountProduced(); totalAmountProduced += amountProduced; Commodity.getCommNum(producedCommodity).incMakerNum(amountProduced); Model.instance().addToActors(this); // Model.instance().addToProducers(producedCommodity, this); }
@Test public void shouldGetDispenseActivity() throws Exception { Commodity commodity = mock(Commodity.class); CommodityAction dispensingActivity = new CommodityAction(commodity, "12", "12", DataElementType.DISPENSED.getActivity()); when(commodity.getCommodityActionsSaved()) .thenReturn(new ArrayList<>(Arrays.asList(dispensingActivity))); Dispensing dispensing = new Dispensing(); DispensingItem dispensingItem = new DispensingItem(commodity, 10); dispensingItem.setDispensing(dispensing); dispensing.addItem(dispensingItem); assertThat( dispensingItem.getActivitiesValues().get(0).getCommodityAction().getActivityType(), is(DataElementType.DISPENSED.getActivity())); }
private void fillDbTables() throws Exception { for (Category cat : categories) categoryDAO.create(cat); for (Producer p : producers) producerDAO.create(p); Long idProducer = producerDAO.getByName("Apple").getId(); Long idCategory = categoryDAO.getByName("Tablet").getId(); commodity.setIdProducer(idProducer); commodity.setIdCategory(idCategory); commodityDAO.create(commodity); commodity = commodityDAO.getByName("Ipad4"); commodityView.setIdCommodity(commodity.getId()); }
public void earnIncome() { // If they didn't empty their inventory, lower price // Model.instance().showNumOfProducers(); String message; if (Model.instance().findProducer(producedCommodity, this) && Model.instance().getTick() > 1) { // cph Decrease price by changeProp to represent unsold inventory expPrice[producedCommodity] /= changeProp; if (producedCommodity == GOOD) { message = "Due to surplus inventory, price of " + Integer.toString(GOOD) + " falls to " + Double.toString(expPrice[producedCommodity]); debug(message, PRICE); } } /*if((producedCommodity != 5) && (Model.instance().getNumProducers(producedCommodity)>15)){ producedCommodity = 5; }*/ if (Model.instance().generateSwitch() < Model.SWITCH_PROZ && Model.instance().getTick() > 1) { // Remove from current production arrayList int com = 0; double max = 0; for (int i = 0; i < Commodity.NUM_COMM; i++) { if (expPrice[i] > max) { com = i; max = expPrice[i]; } } Model.instance().removeFromProducers(producedCommodity, this); producedCommodity = com; } if (Model.instance().findProducer(producedCommodity, this)) { } else { // Add to new production arrayList Model.instance().addToProducers(producedCommodity, this); } if (producedCommodity == 0) { // System.out.println("I produce A!"); } else { // System.out.println("I produce something else!"); } // if(age > 3 && producedCommodity == 1){ // }else{ commoditiesHeld[producedCommodity] += amountProduced; // Units? Commodity.getCommNum(producedCommodity).produce(amountProduced); totalMoney += money; makeBudget(); // } }
// Remove half of every commodity and send that info to the commodity public void consume() { for (int i = 0; i < Commodity.NUM_COMM; i++) { // double prop = commoditiesHeld[i]/2; double prop = commoditiesHeld[i]; // double prop = 10; Commodity.getCommNum(i).consumeProp(prop); commoditiesHeld[i] -= prop; // commoditiesHeld[i]-=10; /*if(commoditiesHeld[i]-Commodity.getCommNum(i).getAmtCons()>=0) { commoditiesHeld[i]-=Commodity.getCommNum(i).getAmtCons(); Commodity.getCommNum(i).consume(); } else { Commodity.getCommNum(i).consFail(commoditiesHeld[i]); commoditiesHeld[i]=0; //considerDeath(); }*/ } }
@Test public void testUpdate() throws Exception { commodityViewDAO.create(commodityView); List<CommodityView> c = commodityViewDAO.getByIdCommodity(commodity.getId()); CommodityView view = c.get(0); long id = view.getId(); long idCommodity = view.getIdCommodity(); someCommodityView = new CommodityView(); someCommodityView.setId(id); someCommodityView.setIdCommodity(idCommodity); someCommodityView.setCommodityPhoto(view.getCommodityPhoto()); someCommodityView.setCommodityPhotoType(ImageType.png); someCommodityView.setGalleryPhoto(true); commodityViewDAO.update(someCommodityView); CommodityView test = commodityViewDAO.getById(id); assertEquals(someCommodityView, test); }
private void parseCommodityNode(final XMLStreamReader reader) { Map<String, String> elementMap = new HashMap<>(); /* still at start of the element. Need to know when end is reached */ QName parsingElement = reader.getName(); try { while (reader.hasNext()) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: String element = reader.getLocalName(); elementMap.put(element, reader.getElementText()); break; case XMLStreamConstants.END_ELEMENT: if (reader.getName().equals(parsingElement)) { logger.finest("Found the end of a CommodityNode"); Commodity node = new Commodity(); node.symbol = elementMap.get("symbol"); node.description = elementMap.get("description"); node.prefix = elementMap.get("prefix"); node.suffix = elementMap.get("suffix"); node.scale = Byte.parseByte(elementMap.get("scale")); // place in the map commodityMap.put(node.symbol, node); return; } break; default: break; } } } catch (XMLStreamException e) { logger.log(Level.SEVERE, e.toString(), e); } }
@Test public void shouldNotBeExemptedFromSalesTaxIfCommodityIsMusicCd() { Commodity commodity = new Commodity("music CD", 14.99); assertEquals(false, commodity.isExemptedFromSalesTax()); }
@Test public void shouldHaveSalesTaxIfCommodityIsNotExemptedFromSalesTax() { Commodity commodity = new Commodity("bottle of perfume", 18.99); assertEquals(1.90, commodity.computeSalesTax(), 0.0001); }
private void selectProducer(Human seller, int good) { double price = seller.expPrice[good]; double quantity = budgetExp[good] / price; double otherQuantity = seller.budgetExp[good] / price; // seller.chokeQuant[good]; String message; /*double quantity = chokeQuant[good]; double otherQuantity = seller.chokeQuant[good]; //How much is the buyer willing to buy at the price for(int i=0; i<Commodity.NUM_COMM; i++){ if(i!=good){ quantity -= demandSlope[i]*expPrice[i]; }else{ quantity -= demandSlope[good]*price; } }*/ /*for(int k=0; k<Commodity.NUM_COMM; k++){ otherQuantity -= seller.demandSlope[k]*seller.expPrice[k]; }*/ double firstQuantity = quantity; if (otherQuantity > (seller.commoditiesHeld[good] - quantity)) { quantity = (seller.commoditiesHeld[good] - quantity); // Remove seller from producer arrayList // cph Seller sold inventory, raises price to reflect scarcity of his good seller.expPrice[good] *= changeProp; if (good == GOOD) { message = "Producer of good " + Integer.toString(GOOD) + " ran out, price rises to " + Double.toString(seller.expPrice[good]) + " wanted to hold quantity " + Double.toString(quantity) + " not " + Double.toString(firstQuantity); debug(message, PRICE); } Model.instance().removeFromProducers(seller.producedCommodity, seller); debug("removing", false); } double diff = price - expPrice[good]; diff /= 10; double tempUnDiff = expPrice[good]; // expPrice[good]+=diff; if (good == 2) { message = "2 price changed from " + Double.toString(tempUnDiff) + " to " + Double.toString(expPrice[good]); debug(message, TRADE); message = "2 price changed by " + Double.toString(diff); debug(message, TRADE); // System.out.printf("2 price changed from %f to %f\n", tempUnDiff, expPrice[good]); // System.out.printf("2 price changed by %f\n", diff); } // If they bought, raise seller's price if (quantity > 0) { // && money >= price*quantity){ // System.out.printf("We bought %f at %f!\n",quantity, price); seller.commoditiesHeld[good] -= quantity; commoditiesHeld[good] += quantity; budgetExp[good] -= quantity * price; seller.money += quantity * price; money -= quantity * price; Commodity.getCommNum(good).reportSale(quantity); totalSpent += quantity * price; // seller.expPrice[good]*=1.01; } else { // System.out.printf("We didn't buy at %f!\n", price); } }
@Test public void shouldBeExemptedFromSalesTaxIfCommodityIsChocolateBar() { Commodity commodity = new Commodity("chocolate bar", 0.85); assertEquals(true, commodity.isExemptedFromSalesTax()); }
@Test public void shouldBeExemptedFromSalesTaxIfCommodityIsHeadachePills() { Commodity commodity = new Commodity("headache pills", 9.75); assertEquals(true, commodity.isExemptedFromSalesTax()); }
@Test public void shouldBeExemptedFromSalesTaxIfCommodityIsBoxOfChocolates() { Commodity commodity = new Commodity("box of chocolates", 10.00); assertEquals(true, commodity.isExemptedFromSalesTax()); }
@Test public void shouldHaveNoSalesTaxIfCommodityIsExemptedFromSalesTax() { Commodity commodity = new Commodity("chocolate bar", 0.85); assertEquals(0.0, commodity.computeSalesTax(), 0.001); }
@Test public void shouldBeExemptedFromSalesTaxIfCommodityIsBook() { Commodity commodity = new Commodity("book", 12.49); assertEquals(true, commodity.isExemptedFromSalesTax()); }
@Transient public String getCommodityTypeName() { return commodity.getCommodityType().getCommodityTypeName(); }
@Transient public String getUnitName() { return commodity.getUnit().getUnitName(); }
public int worth() { return getUnits() * _commod.getUnitValue(); }