Q:

Declaring a variable via Scanner?

I'm trying to set my int "n" to be defined by a users input. however it is never set and I'm not sure what's wrong. I'M NOT very good at java and this IS homework. I think my problem is very basic but I'm stuck.
So, to restate my question. Why can't I set my int n to be a user input? The "n" problem isn't the actual homework but in order for my homework to work correctly, "n" has to be set.
package printer.java;

import java.util.Queue;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Random;
import java.util.Scanner; 

public class PrinterJava {
// Declaring ints needed
int count = 0;
int jobCount = 0;
int done = 0;
int time = 0;
int jobTimerDelay = 1000;
int jobTimerPeriod = 1000;
int timeTimerDelay = 1000;
int timeTimerPeriod = n * 60 * 1000;

// declaring timers needed
    Timer jobTimerTimer = new Timer();
    Timer timeTimerTimer = new Timer();
// This is a timer that is supposed to create new "pages" every 5 seconds. 
//the pages have to be a random "size between 1 and 5 pages long"

public void jobTimer() {
    jobTimerTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            count++;
            Random dom = new Random();
            int p = dom.nextInt(5) + 1;
            if (count % 5 == 0) {
                pages page = new pages();  // Creates a new page every 5 seconds
                page.pages = p;
                jobCount++;
                    jobQueue.offer(page); // pushes the newly created pages into the queue
                    System.out.println("A new Job has been created! Job queue size: " + jobQueue.size());
                    System.out.println("Total Jobs created: " + jobCount);
                } else if (!jobQueue.isEmpty() && count > 2 && count % 2 == 0) {
                    done++;
                    jobQueue.remove();
                    System.out.println("Job printed successfully! total jobs printed: " + done);
                }
            }
        }, jobTimerDelay, jobTimerPeriod);

   }
    // this is the queue that holds the pages
    Queue<Object> jobQueue = new LinkedList<Object>();

    public class pages { // pages

        int pages;
        // constructor

        public pages() {
        }

        public pages(int NumPages) {
            this.pages = NumPages;
        }
    }

    public void timerTwo() {
timeTimerTimer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                PrinterJava runOne = new PrinterJava(); // creats an instance of my page creator
                runOne.jobTimer();
                System.out.println("Please Enter Run time in minutes as an integer: ");
                Scanner scan = new Scanner(System.in); 
                int n = scan.nextInt(); 
            }
        }, timeTimerDelay, timeTimerPeriod);

    }

    public static void main(String[] args) {
        PrinterJava runTwo = new PrinterJava(); // creats an instance of my page creator
        runTwo.timerTwo();
    }
}

A:

This line won't compile because n is not defined yet:
int timeTimerPeriod = n * 60 * 1000;

However, if it would this won't work as expected either:
timeTimerTimer.scheduleAtFixedRate(new TimerTask() {...}, timeTimerDelay, timeTimerPeriod);

Because n is defined inside TimerTask.run() method. To solve this consider make this changes:
int timeTimerPeriod = 60 * 1000; // instance variable
int n = 0;

...

public void timerTwo() {
    System.out.println("Please Enter Run time in minutes as an integer: ");
    Scanner scan = new Scanner(System.in); 
    n = scan.nextInt(); // <-- read n here for first time

    timeTimerTimer.scheduleAtFixedRate(new TimerTask() {...}, timeTimerDelay, timeTimerPeriod * n);
}

