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

Write a program to answer questions like the following: Suppose the species Klin

ID: 3630467 • Letter: W

Question

Write a program to answer questions like the following: Suppose the species Klingon ox has a population of 100 and a growth rate of 15 percent, and the species elephant has a population of 10 and a growth rate of 35 percent. How many years will it take for the elephant population to exceed the Klingon ox population? Use the CLASS SPECIES IN LISITING 5.19. Your program will as for the data on both species and will respond by telling you how many years it will take for the species that starts with the lower population to outnumber the species that starts with the higher population. The two species may be entered in any order. It is possible that the species with the smaller population will never outnumber the other species. In this case, your program should display a suitable message stating this fact.

Explanation / Answer

import java.util.*;

class population{

        public static void main(String[] args) {

                int fsum = 0;
                int ssum = 0;
                double frate = 0;
                double srate = 0;
                int years =0;
                int difference = 0;

                Scanner sc = new Scanner(System.in);
                System.out.print("Type the first species population :");
                fsum = sc.nextInt();
                System.out.print("Type the first species growth rate (%): ");
                frate = sc.nextDouble()/100;
                System.out.print("Type the second species population: ");
                ssum = sc.nextInt();
                System.out.print("Type the second species growth rate (%): ");
                srate = sc.nextDouble()/100;

                if(fsum <= ssum){

                        if(frate <= srate){
                                System.out.println("The first species will never outnumber the second species. ");
                        }else {

                                while(difference <= 0){
                                        years ++;
                                        fsum *= (1 + frate);
                                        ssum *= (1 + srate);
                                        difference = fsum - ssum;
                                }
                                System.out.printf("It will takes %d years for first species to outnumber second species. ",years);
                        }
                }else {

                        if(srate< frate){
                                System.out.println("The second species will never outnumber the first species. ");
                        }else{
                                while(difference <= 0){
                                        years ++;
                                        fsum *= (1 + frate);
                                        ssum *= (1 + srate);
                                        difference = ssum - fsum;
                                }
                                System.out.printf("It will takes %d years for second species to outnumber first species. ",years);
                        }
                }
        }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote