Write a Java program that calculates the number of cows over a period specified by the user. The user inputs the initial number of cows and the number of years.

Example Calculation:

1. User enters 10 cows for 2 years.

Year 1:
- Initial cows: 10
- 90% in heat: 10 x 90% = 9
- 90% fertile: 9 x 90% = 8
- 95% serviced by bull: 8 x 95% = 7
- Total cows after year 1: 10 + 7 = 17

Year 2:
- Initial cows: 17
- 90% in heat: 17 x 90% = 15
- 90% fertile: 15 x 90% = 13
- 95% serviced by bull: 13 x 95% = 12
- Total cows after year 2: 17 + 12 = 29

Continue this process for the number of years entered by the user.

Answer :

Here is the Java code that calculates the number of cows for a period of time entered by the user. It takes the initial number of cows, the number of years, and the percentage of cows that are in heat, fertile, and serviced by a bull as input from the user.

It then calculates the number of cows for each year and displays the results.

import java.util.Scanner;

public class CowCalculator { public static void main(String[] args)

{ Scanner input = new Scanner(System.in);

int initialCows; int years; double inHeat

; double fertile; double serviced; System.out.print("Enter the initial number of cows: "); initialCows = input.nextInt();

System.out.print("Enter the number of years: "); years = input.nextInt();

System.out.print("Enter the percentage of cows in heat: ");

inHeat = input.nextDouble() / 100.0;

System.out.print("Enter the percentage of fertile cows: ");

fertile = input.nextDouble() / 100.0;

System.out.print("Enter the percentage of serviced cows: "); serviced = input.nextDouble() / 100.0;

double cows = initialCows; for (int i = 1; i <= years; i++) { double heatCows = cows * inHeat; double fertileCows = heatCows * fertile;

double servicedCows = fertileCows * serviced; cows += servicedCows;

System.out.println("Number of cows for year " + i + ": " + cows); } }}

In this code, the Scanner class is used to read input from the user. The initial number of cows, the number of years, and the percentages of cows in heat, fertile, and serviced by a bull are stored in variables. The program then uses a for loop to calculate the number of cows for each year, based on the previous year's results.

To know more about percentage visit :

https://brainly.com/question/32197511

#SPJ11