Poszedlem za twoja rada i troche przysiadlem do tego mam takie cos :
import java.util.*;
import javax.swing.*;
abstract class Proces extends Thread {
protected String[] inicjaly;
protected Password password;
public Proces(Password password, String[] inicjaly) {
setPassword(password);
setInicjaly(inicjaly);
}
public void setInicjaly(String[] inicjaly) {
this.inicjaly = inicjaly;
}
public void setPassword(Password password) {
this.password = password;
}
}
class Pracownicy {
static String[] inicjaly={"nt"};
static String[] daty={"230990"};
public Pracownicy() {
}
public String[] getInicjaly() {
return inicjaly;
}
public String[] getData() {
return daty;
}
}
class GrupaA extends Proces {
protected int from = 0;
protected int to = 1000000;
public GrupaA(Password password, String[] initials, int from, int to) {
super(password, initials);
this.from = from;
this.to = to;
}
public void run() {
String passCandidate;
while (password.isPassUnknown()) {
for (int x = 0; x < inicjaly.length; x++) {
for (int y = from; y < to; y++) {
passCandidate = inicjaly[x]
+ (("" + (1000000 + y)).substring(1));
if (password.compare(passCandidate)) {
password.setPassBroken();
System.out.println("Hasło złamane: " + passCandidate);
return;
}
}
}
break;
}
}
}
class GrupaAwatki {
protected int threadsNum = 0;
public GrupaAwatki(int threadsNum) {
this.threadsNum = threadsNum;
}
public void startGroups(Password password, String[] initials) {
if (threadsNum == 0) {
threadsNum = initials.length;
}
GroupA[] threads = new GroupA[threadsNum];
int limit = 1000000;
int part = limit / threadsNum;
int from = 0 - part;
int to = 0;
int x = 0;
boolean workFlag = true;
do {
from += part;
if (to + part < limit && x + 1 < threadsNum) {
to += part - 1;
} else {
to = limit;
workFlag = false;
}
threads[x] = new GroupA(password, initials, from, to);
threads[x].start();
x++;
} while (workFlag);
System.out.println("Uruchomiono " + x + " wątków grupy A");
}
}
class GrupaB extends Proces {
public GrupaB(Password password, String[] initials) {
super(password, initials);
}
public void run() {
String passCandidate, input;
String message = "Nasze propozycje haseł";
while (password.isPassUnknown()) {
passCandidate = "";
input = JOptionPane.showInputDialog(message);
if (input == null) {
return;
} else if (password.compare(input)) {
password.setPassBroken();
System.out.println("Hasło złamane: " + passCandidate);
return;
} else {
System.out.println("nie udało się");
}
}
}
}
class Password {
protected boolean passBroken = false;
protected String password;
public boolean compare(String password) {
return this.password.equals(password) ? true : false;
}
public boolean isPassUnknown() {
return !passBroken;
}
public void generate(String[] inicjaly,String[] daty) {
int randomIndex = (int) (inicjaly.length * Math.random());
password = inicjaly[randomIndex]+daty[randomIndex];
}
public String getPassword() {
return password;
}
public void setPassBroken() {
passBroken = true;
}
}
class Timer extends Thread {
protected int counter;
protected Password password;
protected boolean running = true;
public Timer(Password password) {
this.password = password;
}
public void stopTimer() {
this.running = false;
}
public void run() {
while (running && !password.passBroken) {
try {
counter++;
System.out.println("Czas: " + (counter / 60) + ":"
+ (counter % 60));
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class Main {
public static void main(String[] args) {
int threads;
try {
threads = Integer.parseInt(JOptionPane.showInputDialog("Podaj ilosc watkow Grupy A")); // liczba watkow - manualna
} catch (ArrayIndexOutOfBoundsException e) {
threads = 0;
}
Pracownicy employee = new Pracownicy();
Password password = new Password();
password.generate(employee.getInicjaly(),employee.getData());
System.out.println("Wylosowane haslo: " + password.getPassword());
GrupaAwatki grAw = new GrupaAwatki(threads);
GrupaB grB = new GrupaB(password, employee.getInicjaly());
Timer timer = new Timer(password);
timer.start();
grAw.startGroups(password, employee.getInicjaly());
grB.setPriority(8);
grB.start();
}
}
Co bys zmienil ? Teraz program dziala prawidlowo . Jedna grupa wpisuje haslo recznie druga wyszukuje automatycznie.