Parse the given SWIFT loan message - Java Quiz Question



Write a program to parse the given SWIFT loan message and create the corresponding loan object. For display purposes new lines are shown as $.

Input (String) Output (Loan)

:20:895PGT
:21:LOAN FOR BANK
:22A:NEWT89045
:94A:PGT895 TO PARTYB
:22B:CONF8978
:22C:895PGTPARTYB
:82A:STATE BANK OF HYDERABAD
GNT STREET
KUKATPALLY
HYDERABAD 98359734
:87A:ANDHRA BANK
MG ROAD
NELLORE 8845688
:83A:76345762345

Sender Reference=895PGT
Related Reference=LOAN FOR BANK
Type Of Operation=NEWT89045
Scope Of Operation=PGT895 to PARTYB
Type Of Event=CONF8978
Common Reference=895PGTPARTYB
Party A=STATE BANK OF HYDERABAD$GNT STREET$KUKATPALLY$HYDERABAD 98359734
Party B=ANDHRA BANK$MG ROAD$NELLORE 8845688
Instructing Party=76345762345

:20:346HMK
:22A:JHJ9080
:94A:346HMK TO PARTYB
:22B:CONF8768
:22C:346HMKPARTYB
:82A:ING VYSYA BANK
SOUTH ZONE
KAVALI 98359734
:87A:HDFC BANK
BEACH ROAD
KAVALI 346456
:83A:876885685

Sender Reference=346HMK
Related Reference=null
Type Of Operation=JHJ9080
Scope Of Operation=346HMK to PARTYB
Type Of Event=CONF8768
Common Reference=346HMKPARTYB
Party A=ING VYSYA BANK$SOUTH ZONE$KAVALI 98359734
Party B=HDFC BANK$BEACH ROAD$KAVALI 346456
Instructing Party=876885685

:20:235LHJB
:21:LOAN FOR BANK
:22A:776KLJ
:22B:CONF7663
:22C:235LHJBPARTYB
:82A:GRAMEENA BANK
SR ROAD
KAKINADA 568567
:87A:HDFC BANK
JK ROAD
KOVVURU 77567
:83A:748458568
   
Sender Reference=235LHJB
Related Reference=LOAN FOR BANK
Type Of Operation=776KLJ
Scope Of Operation=null
Type Of Event=CONF7663
Common Reference=235LHJBPARTYB
Party A=GRAMEENA BANK$SR ROAD$KAKINADA 568567
Party B=HDFC BANK$JK ROAD$KOVVURU 77567
Instructing Party=748458568

:20:899IHKL
:21:LOAN FOR BANK
:22A:8766JOJIO
:94A:899IHKL TO PARTYB
:22B:CONF456
:22C:899IHKLPARTYB
:82A:CORPORATION BANK
CHENNAI
TAMIL NADU 567567
:87A:BANK OF INDIA
MG ROAD
HYDERABAD 4578567

Sender Reference=899IHKL
Related Reference=LOAN FOR BANK
Type Of Operation=8766JOJIO
Scope Of Operation=899IHKL to PARTYB
Type Of Event=CONF456
Common Reference=899IHKLPARTYB
Party A=CORPORATION BANK$CHENNAI$TAMIL NADU 567567
Party B=BANK OF INDIA$MG ROAD$HYDERABAD 4578567
Instructing Party=null

class ParseSWIFTLoanMessage

{    public static void main(String s[])
    {
        String input = ":20:895PGT\n:21:LOAN FOR BANK\n:22A:NEWT89045\n:94A:PGT895 TO PARTYB\n:22B:CONF8978\n:22C:895PGTPARTYB\n:82A:STATE BANK OF HYDERABAD\nGNT STREET\nKUKATPALLY\nHYDERABAD 98359734\n:87A:ANDHRA BANK\nMG ROAD\nNELLORE 8845688\n:83A:76345762345";
        Loan payment = getLoan(input);
        System.out.println("The loan details are : " + payment);

    }


public static Loan getLoan(String input) {
//Write code here to parse the SWIFT message and create the loan
}
}
class Loan {

String senderReference;
String relatedReference;
String typeOfOperation;
String scopeOfOperation;
String typeOfEvent;
String commonReference;
String partyA;
String partyB;
String instructingParty;

@Override
public String toString() {
return "Loan [senderReference=" + senderReference + ", relatedReference=" + relatedReference + ", typeOfOperation=" + typeOfOperation + ", scopeOfOperation=" + scopeOfOperation + ", typeOfEvent=" + typeOfEvent + ", commomReference=" + commonReference + ", partyA=" + partyA + ", partyB=" + partyB + ", instructingParty=" + instructingParty + "]";
}
}