Population and Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dexterdreads
    New Member
    • May 2007
    • 5

    Population and Class

    Hi,

    I have an assignment that is somewhat similar to the last guys:

    Write a class that will predict the size of a population of organisms. The class should store the starting # of ogranisms, their average daily population increase(as a percentage), and the number of days they will multiply. The class should have amethod that uses a loop to display the size of the population for each day.
    Test the class in a program that asks the user for the starting size of teh pop., thier avg daily increase, the # of days they will multiply. The program should display the daily pop.

    Input validation: do not accept a number < 2 for the starting size of the pop. do not accept a negative number for avg daily pop increase. Do not accept a # less than one for the # of days they will multiply.
  • dexterdreads
    New Member
    • May 2007
    • 5

    #2
    Originally posted by dexterdreads
    Hi,

    I have an assignment that is somewhat similar to the last guys:

    Write a class that will predict the size of a population of organisms. The class should store the starting # of ogranisms, their average daily population increase(as a percentage), and the number of days they will multiply. The class should have amethod that uses a loop to display the size of the population for each day.
    Test the class in a program that asks the user for the starting size of teh pop., thier avg daily increase, the # of days they will multiply. The program should display the daily pop.

    Input validation: do not accept a number < 2 for the starting size of the pop. do not accept a negative number for avg daily pop increase. Do not accept a # less than one for the # of days they will multiply.

    This is what i have thus far
    import java.util.Scann er;

    public class Population1
    {

    public static void main(String[] a)
    {
    int startPop; //store the population
    int avgIncrease; //store the average daily population
    int days; //store the number of days they will multiply
    String input; //Store data from keyboard
    char YN; //Holds data for yes or no
    int total;

    //Create Scanner object to for keybrd input
    Scanner kb = new Scanner(System. in);
    Population P = new Population();

    do{

    //Get the number of organisms
    System.out.prin t("\nEnter the number of organisms: ");
    startPop = kb.nextInt();

    //Get the number for daily increase
    System.out.prin t("Enter a number for the average daily growth: ");
    avgIncrease = kb.nextInt();
    avgIncrease = avgIncrease / 100;

    //Get the number of days for multiplying
    System.out.prin t("Enter # of days for multiplying: ");
    days = kb.nextInt();




    }
    while(startPop >= 2 || avgIncrease > 0 || days >=1);
    {

    //Does the user want to re-enter data?

    System.out.prin tln("Note:\n(1) Enter ONLY positive numbers.\n" +"(2)Initial "
    + " populaton must be greater than 2. \n" + "(3)"
    + "Number of days must be greater than 1.");
    System.out.prin tln("Would you like to enter numbers again? ");
    System.out.prin t("Enter Y for yes or N for no: ");
    input = kb.next();
    YN = input.charAt(0) ;

    }

    }



    }

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      And what are you having trouble with?

      (Please use the [CODE] tags when posting your code. Just click and drag over your code and hit the # symbol in your Reply box).

      Comment

      • dexterdreads
        New Member
        • May 2007
        • 5

        #4
        I'm not certain of creating a method that uses a loop to display the size of the population for each day.

        Comment

        Working...