Question: I need help to embelish this java program import java.util.Scanner; public class Hwk3 { public static void main (String[] args) { int males, females; //To
I need help to embelish this java program
import java.util.Scanner;
public class Hwk3
{
public static void main (String[] args)
{
int males, females; //To hold males and females
int totalButterflies, sexRatio, ratioVariance;
int genderDifference, matingPairs; //To hold gender difference and mating pairs
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();
totalButterflies = males + females; //This is the total butterflies
sexRatio = males / females;
ratioVariance = males % females;
genderDifference = males - females;
matingPairs = males + females;
System.out.println(" Total Butterflies: " + totalButterflies );
System.out.println("Sex Ratio : " + sexRatio );
System.out.println("Variance : " + ratioVariance );
System.out.println("genderDifference: " +genderDifference );
System.out.println("matingPairs: " + matingPairs );
}
}
by making the additions below. Do not use any methods that have not been covered, only use the methods that are covered in this week's module.
1) Include a new calculation called "Growth factor" by taking the square root of the product (mating pairs). Use DecimalFormat (discussed last week) to make the output of the growth factor be 3 decimal digits.
2) Include a new calculation called "Ratio factor" by dividing the growth factor by the sex ratio, unless the sex ratio is zero. If the sex ratio is zero then set the ratio factor to the square root of the ratio variance. Use DecimalFormat (discussed last week) to make this output be 1 decimal digit.
3) Include a new calculation called the "Potential population" by raising 2 to the power of the ratio factor, after truncating the ratio factor to an integer. Use the pow method with 2 as the first argument, and casting the second argment to do this. Declare potential population as a double and use DecimalFormat to display the potential population as an integer with no decimal digits.
Also you can use showMessageDialog andshowInputDialog for I/O if you have a way to run Java.
Turn in the program listing and sample program outputs including the following sets of data in your submission:
Males=50, Females=15 (the potential population should be 512)
Males=1, Females=10
Males=10,Females=1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
