Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Code: Please make sure output is correct, copy and paste your entire code so it is easy to run and test. se: Multi-Threading using
Java Code: Please make sure output is correct, copy and paste your entire code so it is easy to run and test.
se: Multi-Threading using Java. em: Write a Java program that reads one record at a time from the file xyz (shown at the end of the assignment). Each record has three sections (i.e., three character-strings) and the order of the three sections may be different from one record to the next. However, the number of asterisks at the beginning of each section determines the section number. For example, section 2 within the record is prefixed with two asterisks. Each section ends with a $ symbol and neither asterisks nor the $ are a part of the section. Example of a record: **PQLG 43275+Ifyouaddthirtytoten,thenresultoffiftythreeisincorrects*18960174 The main module separates the three sections and sends sections one, two, and three to the following three threads of Reveal, Expose, and Discover, respectively. For the above record's example, the three sections are : Section one: 18960174 Section two: PQLG 4427 Section three: If you add thirty to twenty, then result of fifty three is incorrect Reveal Thread The message is made up of six integer numbers, The thread computes a value for M as follows: M=( sum of six numbers) mod26. For our example M=[(18)+(9)+(6)+(0)+(17)+(4)]mod26=(46) mode 26=20 Remember that applying mod function on a negative number may produce a nonpredictable number. Therefore, if you have reached to the point that you must apply mod function on a negative number, then the thread needs to be exited and an error message expressing the case needs to be printed. The Reveal thread will: a) replace each integer number with (M - integer number) mod 26 For our example the integer numbers of 18960174arereplacedby [2018]mod26=2[209]mod26=11[206]mode26=14 [200]mod26=20)[2017]mod26=3[20(4)]mod26=24 The resulting values are valid if they are integer numbers in the range of [025] b) Each integer number resulting from the above step represents the location of an alphabet character in the English alphabet. For our example, the replacement of integer numbers produced in step (a) resulting in: (You may show the outcome by uppercase or lowercase letters.) In the case that the Reveal thread completes its task successfully, the output for the Reveal thread is: In the case that the Reveal thread is exited prematurely due to some errors, the output for the Real thread is: Reveal-Section 1 is: 18960174 - Invalid pose Thread This thread breaks its message into two parts: Part 1 and Part2. Partl carries the first token of the message and Part 2 carries the rest of the tokens. If any of the following conditions is true, then a proper error message is printed, and Expose thread will be exited: - Part 1 includes characters other than alphabet letters - The number of characters in the Part 1 is not even - The number of tokens in Part 2 is not 4 - The tokens in Part 2 are not integers. Part 1 is: PQLG Part 2 is: 4427 Both Parts are valid. The goal is to decipher the message PQLG. To do so, 1) The thread creates a matrix 21, named C, out of the positions of the first 2 characters of Part 1 in the English alphabet letters. For our example, the first two letters are PQ and their positions in alphabet letters are 15 and 16 , respectively. Therefore, we make the matrix C=[1516] The thread also creates a square matrix of 22, named S, out of the tokens in Part 2 . For our example: S=[4237] The thread calculates the matrix C=(SC)mod(26) The matrix C=SCmod26=[4237][1516]mod26=[108142]mod26=[412] Therefore, PQ are deciphered into E and M (the letters located in positions 4 and 12 among the English alphabet letters.) The above process is repeated for the next two characters in Partl (i.e., LG). Matrix C changes into C=[116] but matrix S remains the same. Since the matrix S is a 22 matrix then, the Part 1 is always deciphered 2 characters at a time. The matrix C=SCmod26=[4237][116]mod26=[6264]mod26=[1012] Therefore, LG are deciphered into K and M (the letters located in positions 10 and 12 among the English alphabet letters.) As a result, the message PQLG is deciphered into EMKM (The message may be deciphered into a set of characters that does not have any meaning to you. That is okay.) In the case that the Expose thread completes its task and decipher the code, the output for the Expose thread is: Expose - Section 2 is: PQLG 432 7-Deciphered code is: EMKM-valid In the case that the Expose thread is exited prematurely due to some errors, the output for the Expose thread is: Expose - Section 2 is: PQLG 432 7-Invalid Discover Thread This thread receives the character string of Section three as its argument. Section three includes a scrambled password. Discover thread tries to de-scramble the password. The password is always 8 characters long and starts with a lowercase alphabet letter and includes at least one digit and the rest of characters are lowercase alphabet letters. For the example in hand. Section three is: If you add thirty to twenty, then result of fifty three is incorrect The password is de-scrambled as follows: 1. All tokens that represent a digit expressed by alphabet letters (e.g., "two" represents digit 2 ) are replaced by the digit. For the example in hand Section three is : "If you add thirty to twenty, then result of fifty three is incorrect" Using step 1, the section three changes into Section three is : "If you add thirty to twenty, then result of fifty 3 is incomrect" 2. Identify the valid tokens. A valid token starts with a lowercase alphabet letter or a digit. The password is the first character of these tokens and in the order that they appear in the Section three. Using step 2 the valid tokens are shown in red If you add thirty and twenty, result of fifty 3 is incorrect" The preliminary password is: yatatrof 3iii 3. If the length of the de-scrambled password is longer than eight characters, then the first eight characters make the password unless the truncation produces an invalid password. If this is the case, then the last eight characters make the password. If truncation in both cases generates an invalid password, then the de-scrambled password is considered invalid. The valid and invalid passwords are printed with a proper message indicating the validity/invalidity of the password. Using step 3 the password is: yatatrof This is an invalid password because it does not have any digit in it Therefore, the password is 8 characters from the other end: ii3forta // A valid password Discover Thread prints the line of: Discover - Section. 3 is: If you add thirty to twenty, then result of fifty three is incorrect passwd is: ii3 forta - valid For the sake of discussion, let us assume that we cannot find a valid password from either end. In this case Discover thread prints the line of: Discover - Section 3 is: If you add thirty to twenty, then result of fifty three is incorrect - passwd is: atrof33i - invalid Notes: 1. Drop a copy of your program along with the output in the dropbox Assignment-1 in Folio. File xyz You are not permitted to insert space(s) or any other type of delimiters anywhere in the records of the file xyz. *** Everybody says two of the three men are guilty\$*-3 35 -18 2116 6\$* KMLN 12334 17\$ *25 2423222120 S** This is one good example among sixteen of thems ** AZZA 212188 thinking about this assignment\$ ***Today is a good day for having fun for one dayS*70, $,50,8,20,955 GSUN 5 \& 15 S 2,3,5,100,0SMICH7829$ *** This is one good example among sixteen of them\$ *** MSU is a nice place for only four years $ LFord 3219$20,30,90,0,182S * 1232232120S ***One day when the weather was good one of his friends took her to a movie $JJHN 1215115Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started