Question: Assignment 2: Butterflies vs Bees Contest For this assignment, you will be building a class, creating objects, doing comparisons and doing some calculations. You need
Assignment 2: Butterflies vs Bees Contest
For this assignment, you will be building a class, creating objects, doing comparisons and doing some calculations. You need to remember what you have learned in class, lab, books and your assignments. Be sure to refer to them when you need to.
For this assignment, you will use the following:
- String operations
- Classes and Objects
- Methods
- Math operations
There are 2 parts to this assignment. In the first part, you are going to be given a problem and you will then need to create a structure and write algorithms to solve it. In the second part, youll be turning this algorithm into a java program.
So lets get started!
Part 1: Your Butterflies vs Bees Contest!
During the pandemic, your little sister hasnt 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. Youve 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. Heres what you need to know for each (hint: some of these can be passed/given to the class constructor):
- Human User/Player
- Name - Youll need to ask who is going to play the game
- Whether they want to be a butterfly or bee
- Butterflies
- Butterfly colony name - Every colony needs a name, right? So youll 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. Youll want to integrate the colors into the butterfly colony name. So youll 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 wont know this information, so well need to generate it.
- Bees
- Bee colony name - Every colony needs a name, right? So youll 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 3 7 grams. Users wont know this information, so well need to generate it.
- Flower
- Flower name/type Well 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 wont know this, so well 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)
- User Information - Start by asking the user for their name and whether they want to be on team butterflies or team bees
- 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
- Flower Information Ask the user for the names, colors and distance of 3 flowers they want used in the contest.
- 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.
- 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 5% 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 15% of their nectar.
- 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 colonys collective pot at the end of that round
- Ending colony size - At the end of the 3 rounds, youll determine who wins and calculate the ending colony sizes.
- Whichever colonys 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
- Winning Output - For your last output (nicely formatted in a JOptionPane), you will want to include:
- Whether the users team won or lost (including the user and colony name)
- For both teams
- The starting size
- Total carrying capacity
- Total distance flown
- Total amount of pollen collected
- The ending size
For this program, youll 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. Youll 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 dont try to finish this in one sitting. It will make it MUST easier.
Part 2: Creating your Butterfly Colony program
Once you are done writing and testing your class structure and algorithm, you are ready to start coding!
- Once again, you first you need to create a project. Heres a nice tutorial on how to do that in Netbeans. If you are using Dr. Java or Eclipse, just do a quick search on youtube.com and youll find lots of candidates.
http://www.youtube.com/watch?v=ezUHG1cuxkM
Be sure to give your project a nice, meaningful name (and make sure it adheres to Javas naming conventions).
- Once you have your shell ready, there are a few things to know before you start translating your algorithm into code
- At the top of your class file, be sure to include the following:
//********************************************************************************
// 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.
//********************************************************************************
- Remember I told you that you would be given a method that generates a random number? Heres what you need to do to use it:
- Include the following code at the top of your class file (so that you can use this class:
import java.util.Random;
To find out more about this, go to http://java.sun.com/javase/7/docs/api/index.html (like you did in Lab Assignment 2)
- Youll need to use some variables. Heres how you get a random number:
| Upper limit of the random number generated (exclusive) |
Random r = new Random();
int x = 1 + r.nextInt(10);
Note that the number in the parens (e.g., 10 above) is the upper limit of the random number, exclusively. So, the random number that you get here will be an integer between 1 and 10, once you add the 1. Need a larger range? Just change the 10 to the top of your range.
Heres another example, in this case if you are printing a random number to the console:
System.out.print( 1 + r.nextInt(5) + " " );
- Youll need to use an if-else statement. We havent covered that yet, so heres the structure:
if( variableName1 < variableName2){
// put in what is done if the value of
// variableName is less than the value of
// variableName2
}else{
// put in what is done if the value of
// variableName is greater than or equal to the
// value of variableName2
}
(hint: think about what you need to do with Feed and Breed)
- Now start translating your algorithm into java code.
- Remember to code and then compile frequently. It will make it easier to find any bugs.
- Also remember that you will need to create at least one separate class (where your main method will reside).
- Once you get your program running correctly, there is one more thing to do. Any input requested from the user and/or output received from the user should be in a window (see E.1.14 and E.1.15 from lab 1). At this point, you probably have your output going to the console. For your final submission, it needs to go to a window (JOptionPane). Dont forget any additional libraries that you need to import to do this.
Thats it! Now you can nurture your own butterfly colony, and, chances are, theyll do just fine as your sisters pet! Of course, youll also need to turn it in to Moodle.
Submission Requirements
You must upload a zip file to Canvas that includes your complete source project in Netbeans, ready to load, and also contains the output in separate data files, and your Word/Open Office document with your algorithm.
VERY IMPORTANT: If you do not provide output in separate, easy to find data files, I will assume that your program does not work on those test cases, and grade accordingly. Do not embed the output in your source code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
