Question

Create java code Make sure it runs Part 1: Your little sister has decided that she...

Create java code

Make sure it runs

Part 1:

Your little sister has decided that she wants a pet. You love animals and want to further engender her love of animals, but, well, her last pet, goldie the goldfish, didn’t fare too well. So you went on the hunt for a different kind of pet that will fit the bill. Much to your joy, you have found the perfect pet for her… a Bee farm! They are easy to take care of and don’t die off too quickly. Now all that you have to do is build a caretaker program so that she can easily take care of her Bees and see how they thrive (or not!).

Here’s what you need for the Bee farm (hint: these can be be passed/given to the class constructor if you want to challenge yourself):

Queen’s name – Every Bee colony has a queen, and every queen has a name. So you’ll need to ask the user what they want to name their queen Bee.

Colony name – Every pet needs a name, right? So you’ll need to ask the user what the name of their colony is.

Caretaker name – You’ll need to ask who the colony’s mom/dad is.

Starting size – How many Bees is the colony starting out with? This can vary, so you better ask the user about that also.

These are the things that can be done with the Bee farm:

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

Feed – Like all pets, Bees get hungry. In our case, though, only when the queen is going to breed. Fortunately, with the program you are building, you can ask the user how many days their colony should be fed and then check to make sure they have enough food for the queen to breed and have babies (they need 1 day of food for each time she breeds).

Breed – Other than eating, queen Bees don’t do much else but breed and have babies. You’ll want to be sure she has some entertainment, so you’ll need to ask your user if they want to breed their queen Bee and, if so, how many times. For each time she successfully breeds and has babies, the colony triples in size. (hint: re-read about feeding). Note: As you are not required to use loops, you may limit the number of times the queen breeds to 10 if you can’t figure out another way of doing this (also see lifespan below).

Harvest – You love the bees, but especially love that they make honey. You’ll want to be sure that you harvest your honey. First, the bees only produce honey if they have been fed appropriately. For every ounce of honey, the bees need to have been fed for two days.

Lifespan – Although we love our Bees, they don’t always live very long. In fact, the colony depends on the life of the queen. Queens can only live about 10days. So if the caretaker gives the colony food for more than 10 days, the queen will die. If that happens, then 50% of the Bees will die.

Expand Colony – Additional hives can be added to the Bee farms, allowing the Bees to expand the colony. Ask your user if they want to add an additional hive.

If the colony IS expanded, there is a 70% chance that a new queen will be born.

If the colony IS NOT expanded, there is a 20% chance that a new queen will be born.

(hint: you can use the random number generator from Assignment 1 to help you with this)

New Queen - If a new queen is born, the new queen’s name will be the name of the original queen with “2.0” added to the end of the name.

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 feed your colony again?” You will only ask them ONCE for the needed information and then tell them how their colony is doing.

For your output (nicely formatted in a JOptionPane), you will want to include:

Caretaker Name

Bee Colony Name

Queen’s Name

Starting Size

How many days they were fed

Requested number of times to breed

How many times they successfully bred

How much honey you could harvest

Whether the queen got sick and how many died

Whether the colony was expanded

Whether a new queen was born and what her name is

Final number of Bees in the colony

For Part 1, create a class structure and algorithms for your BeeFarm class, and then do several iterations of tests (i.e., analyze it and step through to make sure that it is logically correct).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your solution : : :

////// Code //////

import java.util.Scanner;
import javax.swing.JOptionPane;
class BeeColony
{
    String queenName;
    String colonyName;
    String careTakerName;
    int startingSize;
    int feedDays;
    public BeeColony(String qn,String cn, String ctn,int s)
    {
        queenName=qn;
        colonyName=cn;
        careTakerName=ctn;
        startingSize=s;
        feedDays=0;
    }
    public void display()
    {
        System.out.println("Queen's Name: "+queenName);
        System.out.println("Colony's Name: "+colonyName);
        System.out.println("CareTaker's Name: "+careTakerName);
        System.out.println("Starting Size: "+startingSize);
    }
    private void feed(int n)
    {feedDays+=n;
    }
    public void breed(int n){
        int numDied=0;
        if(n>10)
            n-=(10-n);
            for(int i=0;i<n;i++)
            {
                startingSize*=3;
                feed(1);
                if(feedDays==10)
                {   numDied=startingSize*70/100;
                    startingSize-=(numDied);
                    break;
                }
            }
      
        System.out.println("Number of days fed: "+feedDays);
        System.out.println("Requested number of times to breed: "+n);
        System.out.println("Number of times they successfully breed: "+feedDays);
        if(feedDays==10)
            System.out.println("The queen got sick and number of bees died is "+numDied);
      
    }
    public int getSize()
    {
        return startingSize;
    }
    public String getQueenName()
    {
        return queenName;
    }
    public boolean expand(boolean s) {
       if(s==true)
           return true;
       else
           return false;
    }
  
}
public class BeeFarm {

    public static void main(String[] args) {
    BeeColony beeColony=new BeeColony("Mary","Cute Bees","Jhon",10);
    beeColony.display();
    beeColony.breed(10);
    int choice;
    boolean newQueens;
    Scanner scan=new Scanner(System.in);
    System.out.println("Do you want to expand the colony? <1 or 2> ");
    choice=scan.nextInt();
  
    if(choice==1)
    {
        System.out.println("The colony is expanded successfully ");
       newQueens=beeColony.expand(true);

       beeColony.startingSize+=1;
    }
    else
    {
        System.out.println("The colony is not expanded.");
        newQueens=beeColony.expand(false);
    }
    System.out.println("New queens born: "+newQueens);
    System.out.println("with name "+beeColony.getQueenName()+"2.0");
    System.out.println("Final number of bees in the colony: "+beeColony.getSize());
    }
  
}

Output : ::

sravan@sravan-TravelMate-4740:~/Desktop t En)11:19 AM sravan@sravan-TravelMate-4740:/Desktop$ java BeeFarm Queens Name: Mary Colonys Name: Cute Bees CareTakers Name: Jhon starting size: 10 Number of days fed: 10 Requested number of tines to breed : 10 ber of times they successfully breed: 16 The queen got sick and number of bees died 1s 413343 Do you want to expand the colony? <1 or 2> The colony 1s expanded successfully New queens born: true with name Mary2.0 Final number of bees in the colony: 177148 sravan@sravan-TraveLMate-4740:-/Desktops Java BeeFarm Queens Name: Mary Colonys Name: Cute Bees CareTakers Name: Jhon starting Size: 10 umber of days fed: 10 Requested number of times to breed: 10 Number of times they successfully breed: 10 The queen got sick and number of bees dted is 413343 Do you want to expand the colony? <1 or 2> The colony is not expanded New queens born: false with name Mary2. Final number of bees in the colony:177147 sravan@sravan-TravelMate-4740:/Desktop$

Thanks

Please Do Rate my Work ...

Add a comment
Know the answer?
Add Answer to:
Create java code Make sure it runs Part 1: Your little sister has decided that she...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Language : JAVA Part A Create a class CompanyDoc, representing an official document used by a...

    Language : JAVA Part A Create a class CompanyDoc, representing an official document used by a company. Give it a String title and an int length. Throughout the class, use the this. notation rather than bare instance variables and method calls.   Add a default constructor. Add a parameterized constructor that takes a value for title. Use this( appropriately to call one constructor from another. Add a toString(), which returns a string with the title, and the length in parentheses. So...

  • Part I—Prenatal Visit It had been a hectic day for the doctor, and his last patient...

    Part I—Prenatal Visit It had been a hectic day for the doctor, and his last patient was on time for her appointment. “Hi. Sis.” “Hi, Jim. How’s my kid brother?” “Tired—how’s the first-time mom? Have you stopped work yet?” “Come on, Jim, I’m a career woman. Te chemical industry needs me. It’s tough to go cold turkey. When Dave and I decided to have a family, we agreed that I should work as long as I could.” “You’re the size...

  • cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having...

    cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having heard you are taking CS 55, your boss has come to ask for your help with a task. Students often come to ask her whether their GPA is good enough to transfer to some college to study some major and she has to look up the GPA requirements for a school and its majors in a spreadsheet to answer their question. She would like...

  • Make sure to include: Ship.java, ShipTester.java, Location.java, LocationTester.java, Grid.java, GridTester.java, Player.java, PlayerTester.java, battleship.java. please do every...

    Make sure to include: Ship.java, ShipTester.java, Location.java, LocationTester.java, Grid.java, GridTester.java, Player.java, PlayerTester.java, battleship.java. please do every part, and include java doc and comments Create a battleship program. Include Javadoc and comments. Grade 12 level coding style using java only. You will need to create a Ship class, Location class, Grid Class, Add a ship to the Grid, Create the Player class, the Battleship class, Add at least one extension. Make sure to include the testers. Starting code/ sample/methods will be...

  • Exercise #1: Write a C program that contains the following steps (make sure all variables are...

    Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. Commenting out the existing coding, write the code to divide a...

  • Tony and Peggy Sue graduated from a university in Texas last May. She received a degree...

    Tony and Peggy Sue graduated from a university in Texas last May. She received a degree in elementary education, and he graduated from the culinary school. They both now work in the Dallas area. Peggy Sue is a teacher, and Tony is a chef at a resort hotel restaurant. It is Christmas Day and Tony asks Peggy Sue to marry him. She excitedly accepts. They set a wedding date of June 30. Tony is from New York City. He is...

  • Direction: review the eassy prof it and summerize it. Add thesis with it. make changes if...

    Direction: review the eassy prof it and summerize it. Add thesis with it. make changes if posible Title The coporate puzzel When all you believe is people behind you until they turn their back on you. Times are hard when you are not to be worried about anything in life. I had a great job with a very working paid. Things were going smoothly until one day I had a call to my manager’s office saying he will like to...

  • Read the article below and in your own words, (1-2 sentences) what is the "true direction"...

    Read the article below and in your own words, (1-2 sentences) what is the "true direction" or right way to interpret nature, according to Bacon? True Directions Concerning the Interpretation of Nature (1620) Francis Bacon Those who have taken it on themselves to lay down the law of nature as something that has already been discovered and understood, whether they have spoken in simple confidence or in a spirit of professional posturing, have done great harm to philosophy and the...

  • Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin...

    Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...

  • Hi there! I need to compare two essay into 1 essay, and make it interesting and...

    Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT