Skip to content

Conversation

@devin-ai-integration
Copy link

Convert COBOL merge_sort_test.cbl to Java - MBA-18

Summary

This PR converts the COBOL program merge_sort/merge_sort_test.cbl to a functionally equivalent Java program MergeSortExample.java for ticket MBA-18. The conversion preserves the exact three-step workflow:

  1. Create test data: Generates two test files with hardcoded customer records
  2. Merge and sort: Combines files and sorts by ascending customer ID
  3. Sort by contract: Re-sorts merged data by descending contract ID

Key implementation details:

  • CustomerRecord class with 5-digit customer ID, 50-char names, 5-digit contract ID, 25-char comment
  • Fixed-width string formatting to match COBOL's PIC clauses
  • Java Collections framework for sorting operations
  • Same file names and console output behavior as original COBOL

Review & Testing Checklist for Human

  • Verify test data accuracy: Cross-reference the hardcoded customer records in createTestData() with the original COBOL source (lines 185-334) to ensure no transcription errors
  • Compare output formatting: Run both programs and verify the fixed-width console output matches exactly - pay special attention to field widths and padding
  • Test file operations: Verify all 5 output files are created correctly (test-file-1.txt, test-file-2.txt, work-temp.txt, merge-output.txt, sorted-contract-id.txt) with proper content
  • Validate sorting behavior: Confirm merge sorts by ascending customer ID (1,3,5,10,24,25,30,50,75,85,999) and final sort by descending contract ID (12323→247)

Recommended test plan: If possible, compile and run the original COBOL program and compare its console output and generated files with the Java version to verify functional equivalence.


Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    COBOL["merge_sort_test.cbl<br/>(Original COBOL)"]:::context
    Java["MergeSortExample.java<br/>(New Java conversion)"]:::major-edit
    
    TestFile1["test-file-1.txt<br/>(6 customer records)"]:::context
    TestFile2["test-file-2.txt<br/>(5 customer records)"]:::context
    MergeOutput["merge-output.txt<br/>(11 records, sorted by customer ID)"]:::context
    SortedOutput["sorted-contract-id.txt<br/>(11 records, sorted by contract ID desc)"]:::context
    
    COBOL -->|"converted to"| Java
    Java -->|"creates"| TestFile1
    Java -->|"creates"| TestFile2
    Java -->|"merges & sorts"| MergeOutput
    Java -->|"sorts by contract ID"| SortedOutput
    
    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit
        L3[Context/No Edit]:::context
    end

classDef major-edit fill:#90EE90
classDef minor-edit fill:#87CEEB
classDef context fill:#FFFFFF
Loading

Notes

  • Link to Devin run: https://app.devin.ai/sessions/a940d75d0ac44f9b87c72fc8027293cd
  • Requested by: Samir Chaudhry (@schaudhry123)
  • Ticket: MBA-18
  • Critical risk: Manual transcription of test data from COBOL - recommend careful verification of customer records, contract IDs, and comments
  • Testing note: Java program successfully compiles and runs, producing expected console output and file structure, but direct comparison with COBOL output would provide highest confidence

- Implement MergeSortExample.java with exact functional equivalence to COBOL program
- Add CustomerRecord class with 5-digit customer ID, 50-char names, 5-digit contract ID, 25-char comment
- Implement createTestData() method with same test records as COBOL version
- Add mergeAndDisplayFiles() method using Collections.sort() for ascending customer ID
- Add sortAndDisplayFile() method using reversed Comparator for descending contract ID
- Maintain fixed-width formatting and console output behavior
- Use same file names: test-file-1.txt, test-file-2.txt, merge-output.txt, sorted-contract-id.txt
- Include proper error handling for file operations

Addresses ticket MBA-18

Co-Authored-By: Samir Chaudhry <[email protected]>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant