I wrote this:
Code:
import java.util.*; //Needed for Scanner Class
public class population //Begin class Population
{
public static void main (String[] args)
//Begin main function
{
//Variable declartion
int starting,avg_daily, no_days;
//create Scanner class for keyboard input
Scanner keyboard = new Scanner(System.in);
//Get a population
System.out.println("Enter starting population of organisms: ");
starting = keyboard.nextInt();
//input validation
if (starting<2)
{
//Display invalid messages
System.out.println("Invalid Renter:");
starting = keyboard.nextInt();
}
//Input average daily population
System.out.println("Enter average daily population: ");
avg_daily = keyboard.nextInt();
if (avg_daily<0)//Validating daily percentage
{
System.out.println("Invalid Renter: ");
avg_daily= keyboard.nextInt();
}
avg_daily=(avg_daily*starting)/100;
//Inputting number of days
System.out.println("Enter number of days: ");
no_days = keyboard.nextInt();
for(int i=0;i<no_days;i++)//loop repeats for all days
{
System.out.println("Day " + (i+1) +":" + starting);
starting=starting+avg_daily;
}
}//End main function
}//end class Population
How would I write this so that it uses dialog boxes for the input questions? I know I would import javax.swing.JOptionPane; ... but if I put JOptionPane.showMessageDialog instead of System.out.println it will obviously give me errors, how do i fix that.