import [Link].
Scanner;
public class ChickenEggBusiness {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Part1
while (true) {
[Link]("Enter the number of chickens or press 0 to exit");
int chickens = [Link]();
if (chickens == 0) {
break; // this will end the program if the user inputs 0
}
[Link]("Enter the average number of eggs laid per chicken per
day: ");
int eggsPerChicken = [Link]();
[Link]("Enter the pounds of feed per chicken per day: ");
double feedPerChicken = [Link]();
[Link]("Enter the cost per pound for feed: ");
double costPerPoundFeed = [Link]();
[Link]("Enter the cost per empty egg carton: ");
double emptyCartonCost = [Link]();
// Display the inputs
[Link]("\n--- Your Inputs ---");
[Link]("Number of Chickens: " + chickens);
[Link]("Eggs per Chicken per Day: " + eggsPerChicken);
[Link]("Pounds of Feed per Chicken per Day: " +
feedPerChicken);
[Link]("Cost per Pound for Feed: $" + costPerPoundFeed);
[Link]("Cost per Empty Carton: $" + emptyCartonCost);
// Step 3 calculate the monthly cost
final int dayMonth = 30;
// feed per month
double totalFeedCost = chickens * feedPerChicken * dayMonth *
costPerPoundFeed;
// the total eggs laid and dozens
int totalEggsLaid = chickens * eggsPerChicken * dayMonth;
int dozenEggs = totalEggsLaid / 12;
double totalCartonCost = dozenEggs * emptyCartonCost;
// total cost for the entire operation each month
double totalCost = totalFeedCost + totalCartonCost;
// calculate the cost for each dozen eggs
double costPerDozenEggs = dozenEggs != 0 ? totalCost / dozenEggs : 0;
// print everything
[Link]("\n ------- Monthly Cost Total ------");
[Link]("Total Feed Cost for the Month: $%.2f\n",
totalFeedCost);
[Link]("Total Carton Cost for the Month: $%.2f\n",
totalCartonCost);
[Link]("Total Monthly Cost: $%.2f\n", totalCost);
[Link]("Cost to Make Each Dozen Eggs: $%.2f\n",
costPerDozenEggs);
// Part 2
[Link]("\n ------ Cost per Dozen with the Supplied Feed
Cost Variations -------");
for (int x = -25; x <= 25; x += 5) {
double newFeedMultiplier = 1 + (x / 100.0);
double newFeedCost = costPerPoundFeed * newFeedMultiplier;
double newFeedCostPerMonth = chickens * feedPerChicken * dayMonth *
newFeedCost;
double newCostPerDozen = dozenEggs != 0 ? (newFeedCostPerMonth +
totalCartonCost) / dozenEggs : 0;
[Link]("Feed Cost Change: " + x + "%");
[Link](" New Feed Cost per Pound: $%.2f\n",
newFeedCost);
[Link](" New Monthly Feed Cost: $%.2f\n",
newFeedCostPerMonth);
[Link](" New Cost per Dozen Eggs: $%.2f\n\n",
newCostPerDozen);
}
[Link]("------ END -----\n");
}
[Link]();
[Link]("Goodbye");
}
}