مساعدة بسيطة في كود جافا

هاجر الروقي • منذ 5 سنوات

السلام عليكم ورحمة الله وبركاته

عندي مشروع باستخدام الحوسبة المتوازية لكن فيه مشكلة

مفترض لما ادخل اليوزر والباس ويتحقق مني ويتحقق من الراندوم نمبر

يطبع لي لست الاكاونتز اللي انا مسجلهم بنفس اليوزر

لكن البرنامج يوقف بعد ويلكم

ولكم جزيل الشكر 

 

هذا الكود :

 

package javaapplication12;
import java.util.Random;
import java.util.Scanner;
public class JavaApplication12 {
public static String username;
Scanner input = new Scanner(System.in);
public static boolean a1;
public static void main(String[] args) throws InterruptedException {
final int threadCount = Runtime.getRuntime().availableProcessors();
long startTime = System.currentTimeMillis();
for (int th = 0; th < threadCount; th++) {

new Thread(new User()).start(); }
long endTime = System.currentTimeMillis();
String[] PSE1 = {("BKQRKNM::V"), ("Kwkv"), ("OXKC<G<"),
("RKTOB:Z:")};
User x1 = new User();
System.out.println("Log in:");
String a = x1.usere();
for (int i = 0; i < PSE1.length; i++) {
if ((x1.encrypt(a, 10)).equalsIgnoreCase(PSE1[i])) {
a1 = true; } }
System.out.println(a1);
if (a1 != true) {
System.out.println("run again");
}
Thread th1 = new Thread(new authentication());
long startTime1 = System.currentTimeMillis();
th1.start();
//start second thread after waiting for 2 seconds or if it's dead
try {
th1.join(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//start third thread only when first thread is dead
try {
th1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
long endTime1 = System.currentTimeMillis();
long startTime2 = System.currentTimeMillis();
//System.out.println("enter the password ");
Thread th2 = new Thread(new authenticationpassword());
th2.start();
long endTime2 = System.currentTimeMillis();
try {
th1.join();
th2.join();

} catch (InterruptedException e) {// TODO Auto-generated catch block
e.printStackTrace();
}
/*
System.out.println("Time of thread " + (endTime - startTime) + "milliseconds" + "number of thread" + threadCount);
System.out.println("Time of thread next thread " + (endTime1 - startTime1) + " milliseconds");
System.out.println("Time of thread next thread " + (endTime2 - startTime2) + " milliseconds");
*/
}
static class User implements Runnable {
Scanner input = new Scanner(System.in);
public static String password, cipw;
String[] US = {("Raghad"), ("Amal"), ("Enas"), ("Hajer")};
String[] PS = {("Raghadc00l"), ("Amal"), ("Enas2w2"), ("Hajer0p0")};
String[] PSE1 = {("BKQRKNM::V"), ("Kwkv"), ("OXKC<G<"),("RKTOB:Z:")};
int time;
public static boolean z, a;
public User(int t) {
time = t; }
private User() {
}
public String usere() {
System.out.println("username: ");
username = input.next();
for (int i = 0; i < US.length; i++) {
if (username.equalsIgnoreCase(US[i])) {
z = true; }
}
if (z == true) {
System.out.println("password: ");
password = input.next();
} else {
System.out.println("run again");
}
return password;
}
// Encrypts text using a shift od s
public String encrypt(String text, int s) {
String plainText = text;
// key value should be from 0 to 25
int key = s;
plainText = plainText.toUpperCase();
char[] plainTextChar = plainText.toCharArray();
for (int i = 0; i < plainTextChar.length; i++) {
plainTextChar[i] = (char) (((int) plainTextChar[i] + key - 65) % 26 + 65); }
String result = String.valueOf(plainTextChar);
return result; }
@Override
public void run() {
for (int i = 0; i < time; i++) {
usere();
}} }
// Encrypts text using a shift od s
static class authentication implements Runnable {
Scanner input = new Scanner(System.in);
public static int num;
public void ath() {
// create instance of Random class
Random rand = new Random();
// Generate random integers in range 0 to 99999
int rand_int1 = rand.nextInt(100000);
// Print random integers
System.out.println("The Random Number: " + rand_int1);
System.out.println("Enter Random Number: ");
num = input.nextInt();
if (rand_int1 == num) {
System.out.println(" welcom " + username + " :) ");
} else {
System.out.println(" run again"); } }
@Override
public void run() {
ath(); } }
// Encrypts the password for usre want secur
static class authenticationpassword implements Runnable {
Scanner input = new Scanner(System.in);
public static int num;
public static char[] plainTextChar;
public static String[]hajeraccounts = {"Twitter : 123456 " , "Instagram : 321321 " , "Gmail : 87987858 "};
public static String[]enasaccounts={"Twitter : 123456 " , "Instagram : 321321 " , "Gmail : 87987858 "};
public static String[]amalaccounts={"Twitter : 2587412 " , "Instagram : 456258 " , "Gmail : 741474 "};
public static String[]raghadaccounts={"Twitter : 0147414 " , "Instagram : 4563217 " , "Gmail : 963852741 "};
/*
public void ath1() {
//enter the password to save on array and finsh input do encrptionpassword
System.out.println("enter the password ");
String[] US1 = new String[5];
for (int j = 0; j < US1.length; j++) {
US1[j] = input.next();
String plainText = US1[j];
// key value should be from 0 to 25
int key = 15;
plainText = plainText.toUpperCase();
plainTextChar = plainText.toCharArray();
for (int i = 0; i < plainTextChar.length; i++) {
plainTextChar[i] = (char) (((int) plainTextChar[i] + key - 65) % 26 + 65); }
String result1 = String.valueOf(plainTextChar);
System.out.println(result1); }
}  
*/


public void showpasses() {
    
    switch (username){
        case "Raghad" :  
         for (int i = 0; i < 3 ; i++)
         System.out.println(raghadaccounts[i]);
         
        case "Amal" :   
         for (int i = 0; i < 3 ; i++)
         System.out.println(amalaccounts[i]);
         
        case "Enas" : 
         for (int i = 0; i < 3 ; i++)
         System.out.println(enasaccounts[i]);
         
        case "Hajer" :
         for (int i = 0; i < 3 ; i++)
         System.out.println(hajeraccounts[i]); 
            
    }
        
    
}    
@Override
public void run() {
showpasses();
    //ath1();
}

}
}

ساعد بالإجابة

"إن في قضاء حوائج الناس لذة لا يَعرفها إلا من جربها، فافعل الخير مهما استصغرته فإنك لا تدري أي حسنة تدخلك الجنة."

لايوجد لديك حساب في عالم البرمجة؟

تحب تنضم لعالم البرمجة؟ وتنشئ عالمك الخاص، تنشر المقالات، الدورات، تشارك المبرمجين وتساعد الآخرين، اشترك الآن بخطوات يسيرة !