Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java pseudocode Part 1: Loving your Amoeba Colony! Your little sister has decide

ID: 3755632 • Letter: J

Question

java pseudocode

Part 1: Loving your Amoeba Colony!

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… an amoeba colony! 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 amoebas and see how they thrive (or not!).

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

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 amoebas 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 colony:

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

Feed – Like all pets, amoebas get hungry. In our case, though, only when they are 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 to breed (they need 1 day of food for each time they breed).

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 Rat, 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 Rat 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.

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

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:

Colony Name

Caretaker Name

Starting Size

How many times they were fed

Requested number of times to breed

How many times they successfully bred

Whether they got sick and how many died

Final number of rat in the colony

For Part 1, create a class structure and algorithms for your rat class, 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.

Explanation / Answer

Answer :
import java.util.Scanner;
import javax.swing.JOptionPane;
class AntColony
{
String queenName;
String colonyName;
String careTakerName;
int startingSize;
int feedDays;
public AntColony(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>20)
n-=(20-n);
for(int i=0;i<n;i++)
{
startingSize*=3;
feed(1);
if(feedDays==10)
{ numDied=startingSize*50/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 ants 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 AntFarm {
public static void main(String[] args) {
AntColony antColony=new AntColony("Mary","Cute Ants","Jhon",10);
antColony.display();
antColony.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=antColony.expand(true);
antColony.startingSize+=1;
}
else
{
System.out.println("The colony is not expanded.");
newQueens=antColony.expand(false);
}
System.out.println("New queens born: "+newQueens);
System.out.println("with name "+antColony.getQueenName()+"2.0");
System.out.println("Final number of ants in the colony: "+antColony.getSize());
}
  
}