nebmucoy674
Coder
Hey all,
I want to create a random number and multiply it by a users input; the objective is to:
I want to create a random number and multiply it by a users input; the objective is to:
- Total number of zombies = population - (A random number between: minimum expected survivors and (5 * minimum expected survivors).... So the input is going to be the minimum expected survivors and population. Please tell me what the heck I'm doing wrong. I keep getting a negative number for the number of zombies. Here is the code, which is not finished yet. Thank you!
Java:
import java.util.Random;
import java.util.Scanner;
public class ZombieCalc {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the population of the outbreak area before infection: ");
int population = Integer.valueOf(scan.nextLine());
System.out.print("Enter the minimum expected survivors: ");
int survivors = Integer.valueOf(scan.nextLine());
System.out.print("Enter the average estimated shotgun blasts needed to kill 1 zombie: ");
int shotgun = Integer.valueOf(scan.nextLine());
System.out.print("Enter the number of zombies each survivor can kill each day: ");
int zombiekills = Integer.valueOf(scan.nextLine());
// Where I'm trying to create the random that will still have the range of the input (
// example of user putting in 500 for population and 50 for survivors and I get a negative)
Random rn = new Random();
int randomNum = rn.nextInt(population) + 0;
int totzombies = population - (randomNum * 5);
System.out.println("****** ANALYSIS ******");
System.out.println("Population:");
System.out.println("Total number of Zombies: " + totzombies);
System.out.println("Total number of survivors: " + survivors);
System.out.println(" ");
System.out.println("Supplies:");
System.out.println("Number of days 'till it's over: ");
System.out.println("Lbs of food needed: ");
System.out.println("Gallons of water needed: ");
System.out.println("Ammount of shotguns needed: ");
System.out.println("Amount of shotgun shells needed: ");
}}