I am to create a program which creates multiple threads, has them do work in parallel, and terminates when the last thread is finished, sounds simple right?
Here is the curve... I am supposed to create thread objects using scanner input, and I am at a loss
When I run my code, I get it to run once per item, but given the input It should read each item n number of times: code is below, I really just don't know where to go from here. I am greatful for any advice.
import java.io.*;
import java.util.*;
import java.awt.*;
/**
*
* @author tricket_7
*/
class MyThread extends Thread{
public void run(){
Scanner input = new Scanner(System.in);
//insert up to 10 countries
System.out.println("How many countries are being supported? ");
int[] numCountries = new int[input.nextInt()];
String[] names = new String[10];
int[] numCheers = new int[10];
for(int i = 0; i < numCountries.length; i++){
//creates each thread object
System.out.println("Enter country name: ");
names[i] = input.next();
//creates number of times thread runs
System.out.println("Enter Number of Cheers: ");
numCheers[i] = input.nextInt();
}
for(int i=0; i<numCountries.length;i++){
System.out.println("Go " + names[i] + "!");
}
}
}
public class CheersThread{
public static void main(String[] args) throws InterruptedException {
//How do I take in multiple threads here?
MyThread t = new MyThread();
//How do I start the multiple threads here?
t.start();
}
}