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

This is an Intro Java hw. Please do not use advance concepts like arrays. The co

ID: 3922408 • Letter: T

Question

This is an Intro

Java hw. Please do not use advance concepts like arrays. The code to be modified and instructions are provided. Indenatation and comment

instructions provided as well.

Please make sure to include output(text form).No need to rush but please be sure to follow all the instructions. WIll def leave positive feedback. THanks!

Code Instructions:

How to write comments:

How to Indent:

Code to be modified:

import java.util.Scanner;
public class Hwk3 {
public static void main (String[] args) {
int males, females,pairs;
int diff=0;
Scanner stdin = new Scanner(System.in);

System.out.println(" Butterfly Estimator ");
System.out.print("Enter the estimated males population: ");
males = stdin.nextInt();
System.out.print("Enter the estimated females population: ");
females = stdin.nextInt();

pairs=males*females;

if (males>females)
{
diff = males - females;
System.out.println("Male Difference :" +diff);
}
else if (females > males)
{
diff=females - males;
System.out.println("Female Difference"+diff);
}

System.out.println("Possible mating pairs is : "+pairs);

}
}

Explanation / Answer

Program:

import java.util.Scanner;
import java.text.DecimalFormat;
public class Hwk3 {
   public static void main (String[] args) {
       int males, females,pairs;
       int diff=0;
       double growthfactor,ratiofactor,potentialpopulation;
       Scanner stdin = new Scanner(System.in);
       DecimalFormat df0 = new DecimalFormat("#");
       DecimalFormat df1 = new DecimalFormat("#.0");
       DecimalFormat df3 = new DecimalFormat("#.000");

       System.out.println(" Butterfly Estimator ");
       System.out.print("Enter the estimated males population: ");
       males = stdin.nextInt();
       System.out.print("Enter the estimated females population: ");
       females = stdin.nextInt();

       pairs=males*females;
       growthfactor=Math.sqrt(pairs);

       if (males>females)
       {
           diff = males - females;
           System.out.println("Male Difference :" +diff);
       }
       else if (females > males)
       {
           diff=females - males;
           System.out.println("Female Difference"+diff);
       }
      
       System.out.println("Possible mating pairs is : "+pairs);
       System.out.println("Growth Factor is : "+df3.format(growthfactor));
      
       if (males/females == 0)
       {
           ratiofactor = Math.sqrt(diff);
       }
       else
       {
           ratiofactor = growthfactor/(males/females);
       }
      
       System.out.println("Ratio Factor is : "+df1.format(ratiofactor));
      
       potentialpopulation = Math.pow(2, (int) ratiofactor);
      
       System.out.println("Potential Population is "+df0.format(potentialpopulation));
   }
}

Sample Outputs

1)

Enter the estimated males population: 50
Enter the estimated females population: 15
Male Difference :35
Possible mating pairs is : 750
Growth Factor is : 27.386
Ratio Factor is : 9.1
Potential Population is 512

2)

Enter the estimated males population: 1
Enter the estimated females population: 10
Female Difference :9
Possible mating pairs is : 10
Growth Factor is : 3.162
Ratio Factor is : 3.0
Potential Population is 8

3)

Enter the estimated males population: 10
Enter the estimated females population: 1
Male Difference :9
Possible mating pairs is : 10
Growth Factor is : 3.162
Ratio Factor is : .3
Potential Population is 1

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