+1 (315) 557-6473 

Program To Build Butterflies Vs Bees Contest, Using Java Programming Language Assignment Solutions.


Write a java assignment program to build butterflies vs bees contest, in programming language.

Requirements and Specifications

Part 1: Your Butterflies vs Bees Contest!
During the pandemic, your little sister hasn’t had any friends to play with… except you! Although you dearly love your little sister, she is driving you a bit crazy. She follows you everywhere and all she wants to do is dress you up, put bows in your hair and then put a picture of the result on Facebook. Lucky you, your friends and family think its hilarious! You, not so much. You decide that she needs something more to do, so you are going to make a game for her. You’ve got it! She loves both butterflies and honey bees, so you are going to make a pollen-collecting contest that your sister can play against the computer.
The game will have 4 types of information you need to keep track of: the user, the Butterflies, the Bees and the Flowers. Here’s what you need to know for each (hint: some of these can be passed/given to the class constructor):
  1. Human User/Player
    • Name - You’ll need to ask who is going to play the game
    • Whether they want to be a butterfly or bee
  2. Butterflies
    • Butterfly colony name - Every colony needs a name, right? So you’ll need to ask the user what the name of the butterfly colony is.
    • Butterfly color - Butterflies come in many different colors. To make things simpler, your colony will start with butterflies that only have two colors, a main color and accent color. You’ll want to integrate the colors into the butterfly colony name. So you’ll need to ask the user about which colors they want.
    • Colony starting size - How many butterflies is the colony starting out with? This can vary, so you better ask the user about that also.
    • Carry capacity – Butterflies come in different sizes. So we need to know how much pollen each butterfly can carry, from 1 – 10 grams. Users won’t know this information, so we’ll need to generate it.
  3. Bees
    • Bee colony name - Every colony needs a name, right? So you’ll need to ask the user what the name of the bee colony is
    • Colony starting size - How many bees is the colony starting out with? This can vary, so you better ask the user about that also.
    • Carry capacity – Bees come in different sizes. So we need to know how much pollen each bee can carry, from 2 – 8 grams. Users won’t know this information, so we’ll need to generate it.
  4.  Flower
    • Flower name/type – We’ll need to ask the user what types of flowers to use in the contest. (e.g., Rose, Lily, etc.)
    • Color – Every flower has a color, so ask the user what color the flower should be
    • Distance from colonies - Each flower is a different distance from the colonies, 1 – 5 miles. The user won’t know this, so we’ll have to generate it.
    • Round – Which round the flower was used in (see below).

    Here is the flow of the game and the things that can be done with the game:

    (hint: Do not assume that these must be methods. Think about how they will be used and then decide)

  5. User Information - Start by asking the user for their name and whether they want to be on team butterflies or team bees
  6. Colony Information - Ask the user for names of the butterfly and bee colonies, the colors of the butterflies, and the starting size of the butterfly and bee colonies
  7. Flower Information – Ask the user for the names, and colors of 3 flowers they want used in the contest.
  8. 3 Rounds - There will be 3 rounds where in each round, one butterfly and one bee will race to the selected flower, grab as much nectar as they can carry, and race back to the colony. At the colony, the nectar will be put into a collective pot for each colony.
  9. Nectar Loss – As the butterflies and bees fly back with their colony, they lose some of the nectar that they have picked up. How much they lose depends on how far they have to fly. For every mile they have to fly, they lose 10% of the nectar that they are carrying. For example, if they have to fly 3 miles, then when they have reached the colony, they will have lost 30% of their nectar.
  10. Each Round - For each round, the user should be told the following:
    • Round number
    • Which flower (including its color) the butterflies (the integrated name as discussed above) and bees are racing to
    • The distance to the flower
    • The carrying capacity of the butterfly and bee
    • How much nectar made it back to the colony
    • The amount of nectar in each colony’s collective pot at the end of that round
  11. Ending colony size - At the end of the 3 rounds, you’ll determine who wins and calculate the ending colony sizes.
    • Whichever colony’s collective pot has the most nectar wins.
    • For the winning colony, the colony triples in size. For full credit, you must use the appropriate math function.
    • For the losing colony, the colony loses 10% of its population
  12. Winning Output - For your last output (nicely formatted in a JOptionPane), you will want to include:
    • Whether the user’s team won or lost (including the user and colony name)
    • For both teams
    1. The starting size
    2. Total carrying capacity
    3. Total distance flown
    4. Total amount of pollen collected
    5. The ending size
    For this program, you’ll want to ask your user about any pertinent information up front. Do not worry about having any loops to ask them things like “Do you want to play again?” You will only ask them ONCE for the needed information and then tell them how the game is progressing.
    For Part 1, create the class structures and algorithms for your program, and then do several iterations of tests (i.e., analyze it and step through to make sure that it is logically correct). Also write the pseudocode for your tester class (where your main will go). Put these in a Word or Open Office document. You’ll turn that document in with the program that you create in Part 2.
    Important! As you are working on this, be sure to break this down into smaller pieces. Take it step-by-step, and don’t try to complete your java assignment in one sitting. It will make it MUST easier.
    Source Code
    import javax.swing.*;
    import java.util.Random;
    import java.util.Scanner;
    // Name: [Your Name]
    // FIU email: [Your FIU email]
    // PantherID: [Your PantherID]
    // CLASS: COP 2210 – [Semester Year]
    // ASSIGNMENT # [#]
    // DATE: [Date]
    // I hereby swear and affirm that this work is solely my own, and not the work
    // or the derivative of the work of someone else.
    public class ColonyGame {
        private static final int ROUNDS = 3;
        private enum ColonyType {
        public static void main(String[] args) {
            String name = askForString("Please, enter your name: ");
            ColonyType playerColonyType = askForColonyType("Please, choose your colony (Bees/Butterflies): ");
            Random random = new Random();
            String butterflyColonyName = askForString("Please, enter butterfly colony name: ");
            String butterflyColor = askForString("Please, enter butterfly colony color: ");
            int butterflyStartingSize = askForInt("Please, enter butterfly colony starting size: ");
            Butterflies butterflies = new Butterflies(butterflyColonyName, butterflyStartingSize, random.nextInt(10) + 1, butterflyColor);
            String beeColonyName = askForString("Please, enter bee colony name: ");
            int beeStartingSize = askForInt("Please, enter bee colony starting size: ");
            Bees bees = new Bees(beeColonyName, beeStartingSize, random.nextInt(7) + 2);
            Flower[] flowers = new Flower[ROUNDS];
            for (int i = 0; i < ROUNDS; i++) {
                String flowerName = askForString("Please, enter flower #" + (i + 1) + " name: ");
                String flowerColor = askForString("Please, enter flower #" + (i + 1) + " color: ");
                flowers[i] = new Flower(flowerName, flowerColor, random.nextInt(5) + 1, i + 1);
            int beesDistance = 0;
            int butterfliesDistance = 0;
            for (int i = 0; i < ROUNDS; i++) {
                StringBuilder message = new StringBuilder();
                message.append("Round #").append(i + 1).append(System.lineSeparator());
                message.append("Flower: ").append(flowers[i]).append(System.lineSeparator());
                message.append("Flower distance: ").append(flowers[i].distance).append(System.lineSeparator());
                message.append("Bee capacity: ").append(bees.carryCapacity).append(System.lineSeparator());
                message.append("Butterfly capacity: ").append(butterflies.carryCapacity).append(System.lineSeparator());
                double beesCarried = bees.carryCapacity * (1 - 0.1 * flowers[i].distance);
                beesDistance += flowers[i].distance;
                message.append("Bee carried: ").append(String.format("%.2f", beesCarried)).append(System.lineSeparator());
                double butterfliesCarried = butterflies.carryCapacity * (1 - 0.1 * flowers[i].distance);
                butterfliesDistance += flowers[i].distance;
                message.append("Butterfly carried: ").append(String.format("%.2f", butterfliesCarried)).append(System.lineSeparator());
                bees.colonyPot += beesCarried;
                message.append("Bees colony pot: ").append(String.format("%.2f", bees.colonyPot)).append(System.lineSeparator());
                butterflies.colonyPot += butterfliesCarried;
                message.append("Butterflies colony pot: ").append(String.format("%.2f", butterflies.colonyPot)).append(System.lineSeparator());
                JOptionPane.showMessageDialog(null, message.toString(), "Round result", JOptionPane.INFORMATION_MESSAGE, null);
            StringBuilder message = new StringBuilder();
            String playerColonyName = playerColonyType == ColonyType.Bees ? bees.toString() : butterflies.toString();
            String winLossMessage = name + "! Colony " + playerColonyName + ". ";
            ColonyType winningColony = (bees.colonyPot >= butterflies.colonyPot) ? ColonyType.Bees : ColonyType.Butterflies;
            if (playerColonyType == winningColony) {
                winLossMessage += "You won!";
            } else {
                winLossMessage += "You lost...";
            message.append("Bees starting size: ").append(bees.startingSize).append(System.lineSeparator());
            message.append("Bees total distance flown: ").append(beesDistance).append(System.lineSeparator());
            message.append("Bees total amount of pollen collected: ").append(String.format("%.2f", bees.colonyPot)).append(System.lineSeparator());
            int beesEndingSize = winningColony == ColonyType.Bees ? bees.startingSize * 3 : Math.toIntExact(Math.round(0.9 * bees.startingSize));
            message.append("Bees ending size: ").append(beesEndingSize).append(System.lineSeparator()).append(System.lineSeparator());
            message.append("Butterflies starting size: ").append(butterflies.startingSize).append(System.lineSeparator());
            message.append("Butterflies total distance flown: ").append(beesDistance).append(System.lineSeparator());
            message.append("Butterflies total amount of pollen collected: ").append(String.format("%.2f", butterflies.colonyPot)).append(System.lineSeparator());
            int butterfliesEndingSize = winningColony == ColonyType.Butterflies ? butterflies.startingSize * 3 : Math.toIntExact(Math.round(0.9 * butterflies.startingSize));
            message.append("Butterflies ending size: ").append(butterfliesEndingSize).append(System.lineSeparator()).append(System.lineSeparator());
            JOptionPane.showMessageDialog(null, message.toString(), "Total result", JOptionPane.INFORMATION_MESSAGE, null);
        private static String askForString(String prompt) {
            String result = null;
            while (result == null) {
                result = JOptionPane.showInputDialog(prompt);
            return result;
        private static int askForInt(String prompt) {
            while (true) {
                String result = JOptionPane.showInputDialog(prompt);
                if (result != null) {
                    int a = Integer.parseInt(result);
                    if (a > 0) {
                        return a;
        private static ColonyType askForColonyType(String prompt) {
            while (true) {
                String result = JOptionPane.showInputDialog(prompt);
                if (result != null) {
                    ColonyType ct = ColonyType.valueOf(result);
                    if (ct != null) {
                        return ct;
        private static class Flower {
            String name;
            String color;
            int distance;
            int round;
            public Flower(String name, String color, int distance, int round) {
                this.name = name;
                this.color = color;
                this.distance = distance;
                this.round = round;
            public String toString() {
                return name + " (" + color + ")";
        private static abstract class Colony {
            String name;
            int startingSize;
            int carryCapacity;
            double colonyPot;
            public Colony(String name, int startingSize, int carryCapacity) {
                this.name = name;
                this.startingSize = startingSize;
                this.carryCapacity = carryCapacity;
                this.colonyPot = 0.0;
            public String toString() {
                return name;
        private static class Butterflies extends Colony {
            String color;
            public Butterflies(String name, int startingSize, int carryCapacity, String color) {
                super(name, startingSize, carryCapacity);
                this.color = color;
            public String toString() {
                return name + " (" + color + ")";
        private static class Bees extends Colony {
            public Bees(String name, int startingSize, int carryCapacity) {
                super(name, startingSize, carryCapacity);