Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I have an assignment. It is a team project work but I will ask only the c

ID: 3573716 • Letter: H

Question

Hello, I have an assignment. It is a team project work but I will ask only the coding (ONLY JAVA PLEASE) part of that. I wrote my code and I have done everything what is needed but unfortunately, I cannot reach to result successfully. We need to write a code which takes secret codes that are given. And, then write a code to get some unique special strings from that secret codes and write it to a "agility.txt" file. I have runned the code but It did not work properly. Could you help me to solve my problem? I am going to give the detailed information pdf of the assignment and the code I wrote below:

Dropbox link of the detailed pdf of assignment:

https://www.dropbox.com/s/uh27vk64ny6ow9u/project_018_sprint_3.pdf?dl=0

Alternative onedrive link of the detailed pdf of assignment:

https://1drv.ms/b/s!AoIxLH9P9wW9nxMr2sgyFcweS53e

And here is the code that I wrote below :

import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Date;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class Agility {
public static void main(String[] args) throws IOException {
String base = "TEAM09";
int count = 0;

String userHome = System.getProperty("user.home");
userHome= userHome+"/Desktop";

File f=new File(userHome,"Agility.txt");


FileWriter writer=new FileWriter(f); //file output stream creating

while (true) {
count++;
String trial = base + "STORY" + count;
String trial2= base + "STORY" + count + "DONE" + count;

String trial3= base + "STORY" + count + "DONE" + "VALID" + count;
String trialHash = getSHA256Hash(trial);
String trialHash2= getSHA256Hash(trial2);

String trialHash3= getSHA256Hash(trial3);


if (trialHash.startsWith("55555"))
   writer.write(trial);
   writer.write(System.lineSeparator());
   writer.flush();
   System.out.print(" "+trial);
  
}
if (trialHash2.startsWith("666666")){
   System.out.print(" "+trial2);
   writer.write(trial2);
   writer.write(System.lineSeparator());
   writer.flush();
}
  if (trialHash3.startsWith("7777777")){
System.out.print(" "+trial3);
   writer.write(trial3);
   writer.write(System.lineSeparator());
   writer.flush();
}
PrintLineToFile(trial, "Agility.txt");
writer.flush();  
}
}
public static String getSHA256Hash(String data) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(data.getBytes("UTF-8"));
return bytesToHex(hash);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static String bytesToHex(byte[] bytes) {
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
stringBuffer.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
}
return stringBuffer.toString();
}
}

Could you please help me to fix my mistake?

sincerely...

Dropbox link of the evaluation program of the output text file which is submitted by instructor:

https://www.dropbox.com/s/1ukci4ffgib4fmf/Agility3.exe?dl=0

Onedrive alternative link of the evaluation program of the output text file which is submitted by instructor:

https://1drv.ms/u/s!AoIxLH9P9wW9nx1q8Hfuow7LnrSH

Explanation / Answer

/**********************Agility.java****************/

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.security.MessageDigest;

public class Agility {
   public static void main(String[] args) throws IOException {
       String base = "TEAM09";
       int count = 0;

       String userHome = System.getProperty("user.home");
       userHome = userHome + "/Desktop";

       File f = new File(userHome, "Agility.txt");

       FileWriter writer = new FileWriter(f); // file output stream creating

       while (true) {
           count++;
           String trial = base + "STORY" + count;
           String trial2 = base + "STORY" + count + "DONE" + count;

           String trial3 = base + "STORY" + count + "DONE" + "VALID" + count;
           String trialHash = getSHA256Hash(trial);
           String trialHash2 = getSHA256Hash(trial2);

           String trialHash3 = getSHA256Hash(trial3);

           if (trialHash.startsWith("55555")) {
               writer.write(trial);
               writer.write(System.lineSeparator());
               writer.flush();
               System.out.print(" " + trial);

           }
           if (trialHash2.startsWith("666666")) {
               System.out.print(" " + trial2);
               writer.write(trial2);
               writer.write(System.lineSeparator());
               writer.flush();
           }
           if (trialHash3.startsWith("7777777")) {
               System.out.print(" " + trial3);
               writer.write(trial3);
               writer.write(System.lineSeparator());
               writer.flush();
           }
           PrintLineToFile(trial, "Agility.txt");
           writer.flush();
       }
   }
/**
* This method is used to write lineinto file
* */
   private static void PrintLineToFile(String trial, String file) throws IOException {
       // creating file output Stream for writing output into file
       FileOutputStream fos = new FileOutputStream(new File(file));
       // creating bufferedWriter instance
       BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
       // Writing trial into file
       bw.write(trial);

   }

   public static String getSHA256Hash(String data) {
       try {
           MessageDigest digest = MessageDigest.getInstance("SHA-256");
           byte[] hash = digest.digest(data.getBytes("UTF-8"));
           return bytesToHex(hash);
       } catch (Exception ex) {
           ex.printStackTrace();
       }
       return null;
   }

   public static String bytesToHex(byte[] bytes) {
       StringBuffer stringBuffer = new StringBuffer();
       for (int i = 0; i < bytes.length; i++) {
           stringBuffer.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
       }
       return stringBuffer.toString();
   }
}

Note: we are using infinite while loop, so it will be continue until we closed, so i am attaching some part of output.

/*********************Console output****************/

TEAM09STORY158270
TEAM09STORY2064374
TEAM09STORY2136699
TEAM09STORY2501427
TEAM09STORY3652866
TEAM09STORY3737056
TEAM09STORY4281571
TEAM09STORY4504290
TEAM09STORY4750966
TEAM09STORY6413222
TEAM09STORY6675859
TEAM09STORY9332363
TEAM09STORY10768076
TEAM09STORY12735227

/*********************Agility.txt*******************************/

TEAM09STORY158270
TEAM09STORY2064374
TEAM09STORY2136699
TEAM09STORY2501427
TEAM09STORY3652866
TEAM09STORY3737056
TEAM09STORY4281571
TEAM09STORY4504290
TEAM09STORY4750966
TEAM09STORY6413222
TEAM09STORY6675859
TEAM09STORY9332363
TEAM09STORY10768076
TEAM09STORY12735227

Thanks a lot. If you have any query. Please feel free to ask

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote