Skip to content

Commit

Permalink
Merge pull request #7 from fmintar1/main
Browse files Browse the repository at this point in the history
Committing take 4
  • Loading branch information
fmintar1 authored Nov 13, 2022
2 parents 1d1442d + 1c086e5 commit 861e2d7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 30 deletions.
23 changes: 12 additions & 11 deletions src/main/java/Hammurabi.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,36 @@ public void setUpNewGame() {
this.setYear(0);
this.setPrice(19);
}
public int askHowManyLandsToBuy(int landPurchased) {
public int howManyLandsToBuy(int landPurchased) {
if ((landPurchased * newCostOfLand()) >= getBushels()) {
System.out.println("Because you're trying to buy more than what you can afford, you get nothing and like it!");
return 0;
} else {
setBushels(this.bushels -= landPurchased * newCostOfLand());
setLandsOwned(this.landsOwned += landPurchased);
setBushels(this.bushels - (landPurchased * newCostOfLand()));
setLandsOwned(this.landsOwned + landPurchased);
return landPurchased;
}
}
public int askHowManyLandsToSell(int landSold) {
setLandsOwned(this.landsOwned -= landSold);
public int howManyLandsToSell(int landSold) {
setLandsOwned(this.landsOwned - landSold);
if (this.landsOwned*100/this.population < 70) {
//GAME OVER
return 0;
} else {
setBushels(this.bushels += landSold * newCostOfLand());
setBushels(this.bushels + (landSold * newCostOfLand()));
return landSold;
}
}

public int askHowMuchGrainToFeedPeople(int bushels) {
return 0;
public int howMuchBushelsToFeedPeople(int bushels) {
if (this.bushels < bushels) bushels = this.bushels;
return bushels;
}

public int askHowManyAcresToPlant(int acresOwned, int population, int bushels) {
return 0;
public int howManyLandsToPlant(int landsToBePlanted, int population, int bushels) {

}


public void printSummary() {
//String
}
Expand Down
68 changes: 49 additions & 19 deletions src/test/java/HammurabiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,70 +17,100 @@ public void setUp() throws Exception {
ham = new Hammurabi();
}
@Test
public void askHowManyLandsToBuyTest1() {
public void HowManyLandsToBuyTest1() {
//If price of lands are at maximum of 24
ham.bushels = 1000;
ham.landsOwned = 100;
int landsBought = ham.askHowManyLandsToBuy(40);
int landsBought = ham.howManyLandsToBuy(40);
Assert.assertEquals(40, landsBought);
}
@Test
public void askHowManyLandsToBuyTest2() {
public void HowManyLandsToBuyTest2() {
//If price of lands are at minimum of 17
ham.bushels = 679;
ham.landsOwned = 100;
int landsBought = ham.askHowManyLandsToBuy(40);
int landsBought = ham.howManyLandsToBuy(40);
Assert.assertEquals(0, landsBought);
}
@Test
public void askHowManyLandsToBuyTest3() {
public void HowManyLandsToBuyTest3() {
//If price of lands are random
ham.bushels = 800;
ham.landsOwned = 100;
int landsBought = ham.askHowManyLandsToBuy(40);
int landsBought = ham.howManyLandsToBuy(40);
Assert.assertTrue("Lands bought is " + landsBought,
landsBought == 40 || landsBought == 0);
}
@Test
public void askHowManyLandsToBuyTest4() {
public void HowManyLandsToBuyTest4() {
//Updated lands Owned
ham.bushels = 800;
ham.landsOwned = 100;
ham.askHowManyLandsToBuy(40);
ham.howManyLandsToBuy(40);
Assert.assertTrue("Lands bought is " + ham.landsOwned,
ham.landsOwned == 140 || ham.landsOwned == 100);
}
@Test
public void askaskHowManyLandsToSellTest1() {
public void HowManyLandsToSellTest1() {
//If lands owned after sold is more than 70% of the population
ham.landsOwned = 100;
ham.population = 100;
int landsSold = ham.askHowManyLandsToSell(20);
int landsSold = ham.howManyLandsToSell(20);
Assert.assertEquals(20, landsSold);
}
@Test
public void askaskHowManyLandsToSellTest2() {
public void HowManyLandsToSellTest2() {
//If lands owned after sold is less than 70% of the population
//Game over scenario
ham.landsOwned = 89;
ham.population = 100;
int landsSold = ham.askHowManyLandsToSell(20);
int landsSold = ham.howManyLandsToSell(20);
Assert.assertEquals(0, landsSold);
}
@Test
public void askaskHowManyLandsToSellTest3() {
//If lands owned after sold is less than 70% of the population
public void howManyLandsToSellTest3() {
//Bushels being returned
ham.bushels = 1000;
ham.population = 100;
ham.landsOwned = 100;
ham.askHowManyLandsToSell(20);
System.out.println("Total bushels after sell: " + ham.bushels);
ham.howManyLandsToSell(20);
Assert.assertTrue("Total bushels after sell: " + ham.bushels
, ham.bushels <= 1460 && ham.bushels >= 1340);
}



@Test
public void howMuchBushelsToFeedPeopleTest1() {
//If bushels fed to people are less than stock bushels
ham.bushels = 3000;
ham.population = 1000;
ham.howMuchBushelsToFeedPeople(2000);
Assert.assertEquals(2000, ham.howMuchBushelsToFeedPeople(2000));
}
@Test
public void howMuchBushelsToFeedPeopleTest2() {
//If bushels fed to people are more than stock bushels
ham.bushels = 1500;
ham.population = 1000;
ham.howMuchBushelsToFeedPeople(2000);
Assert.assertEquals(1500, ham.howMuchBushelsToFeedPeople(2000));
}
@Test
public void howManyLandsToPlantTest1() {
//If lands to be planted is more than lands owned
ham.landsOwned = 1000;
Assert.assertEquals(0, ham.howManyLandsToPlant(1001, 999, 1001));
}
@Test
public void howManyLandsToPlantTest2() {
//If lands to be planted is more than population * 10
ham.landsOwned = 1000;
Assert.assertEquals(900, ham.howManyLandsToPlant(1000, 90, 1001));
}
@Test
public void howManyLandsToPlantTest3() {
//If lands to be planted is more than bushels
ham.landsOwned = 1100;
Assert.assertEquals(900, ham.howManyLandsToPlant(1000, 10, 900));
}
@Test
public final void testPlagueDeaths1() {
int number_of_plagues = 0;
Expand Down

0 comments on commit 861e2d7

Please sign in to comment.