ট্র্যাক
/
Ballerina
Ballerina
/
অনুশীলনী
/
XML ফুয়েল অ্যালাউয়েন্স
XML ফুয়েল অ্যালাউয়েন্স

XML ফুয়েল অ্যালাউয়েন্স

মধ্যম

নির্দেশনা

সমস্যার বিবরণ

ABC Corp-এর প্রত্যেক কর্মী সীমাহীন জ্বালানি ভাতা পান। কর্মীরা তাদের গাড়িতে জ্বালানি ভরার প্রতিবারই একটি রেকর্ড পাঠাতে বাধ্য। এই রেকর্ডগুলো একই XML ফাইলে যুক্ত হয় এবং মাসের শেষে প্রক্রিয়া করা হয়।

ডিজিটাল অপারেশনস দলের একজন সদস্য হিসেবে আপনার কাজ হলো এই XML ফাইলটি পড়া এবং ফলাফলগুলো আরেকটি XML ফাইলে লেখা। আউটপুট ফাইলে প্রত্যেক কর্মীর জন্য নিচের তথ্যগুলোসহ একটি এন্ট্রি থাকা উচিত:

আপনাকে দুটি string আর্গুমেন্ট দেওয়া হয়।

  1. ইনপুট XML ফাইলের পাথ।
  2. আউটপুট XML ফাইলের পাথ।

ইনপুট XML ফাইলের কনটেন্টে নিচের XML স্কিমা থাকবে।

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.so2w.org" 
    xmlns:tns="http://www.so2w.org" 
    elementFormDefault="qualified">

    <xs:element name="FuelEvents">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="FuelEvent" type="tns:FuelUpEvent" nillable="true" minOccurs="0" maxOccurs="1000"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="FuelEvent">
        <xs:sequence>
            <xs:element name="odometerReading" type="xs:integer"/>
            <xs:element name="gallons" type="xs:decimal"/>
            <xs:element name="gasPrice" type="xs:decimal"/>
        </xs:sequence>
        <xs:attribute name="employeeId" type="xs:integer" use="required"/>
    </xs:complexType>
</xs:schema>

আপনার কাজ হলো XML ইনপুটকে নিচের XML ফরম্যাটে রূপান্তর করা এবং কনটেন্টটি দেওয়া পাথটিতে লেখা। আউটপুট ফাইলে প্রত্যেক কর্মীর জন্য একটি এন্ট্রি থাকা উচিত, যা employeeId অনুসারে ঊর্ধ্বক্রমে সাজানো।

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   targetNamespace="http://www.so2w.org"
   xmlns:tns="http://www.so2w.org"
   elementFormDefault="qualified">
 
   <xs:element name="employeeFuelRecords">
       <xs:complexType>
           <xs:sequence>
               <xs:element name="employeeFuelRecord" type="tns:employeeFuelRecord" nillable="true" minOccurs="0" maxOccurs="97"/>
           </xs:sequence>
       </xs:complexType>
   </xs:element>
 
   <xs:complexType name="employeeFuelRecord">
       <xs:sequence>
           <xs:element name="gasFillUpCount" type="xs:integer"/>
           <xs:element name="totalFuelCost" type="xs:decimal"/>
           <xs:element name="totalGallons" type="xs:decimal"/>
           <xs:element name="totalMilesAccrued" type="xs:integer"/>
       </xs:sequence>
       <xs:attribute name="employeeId" type="xs:integer" use="required"/>
   </xs:complexType>
</xs:schema>

সীমাবদ্ধতা

  • ইনপুট XML ফাইলে জ্বালানি ভরার রেকর্ডের সংখ্যা n: 0 <= n <= 1000
  • কোম্পানিতে কর্মীর সংখ্যা: 97
  • জ্বালানির দাম প্রতি গ্যালনে
  • কোনো জ্বালানি ভরার রেকর্ড অনুপস্থিত নেই

উদাহরণ ১

  • ইনপুট: example01_input.xml
<s:FuelEvents xmlns:s="http://www.so2w.org">
    <s:FuelEvent employeeId="2312">
        <s:odometerReading>230</s:odometerReading>
        <s:gallons>18.561</s:gallons>
        <s:gasPrice>4.56</s:gasPrice>
    </s:FuelEvent>
    <s:FuelEvent employeeId="2312">
        <s:odometerReading>500</s:odometerReading>
        <s:gallons>19.345</s:gallons>
        <s:gasPrice>4.89</s:gasPrice>
    </s:FuelEvent>
</s:FuelEvents>
  • আউটপুট: example01_output.xml
<s:employeeFuelRecords xmlns:s="http://www.so2w.org">
    <s:employeeFuelRecord employeeId="2312">
        <s:gasFillUpCount>2</s:gasFillUpCount>
        <s:totalFuelCost>179.23521</s:totalFuelCost>
        <s:totalGallons>37.906</s:totalGallons>
        <s:totalMilesAccrued>270</s:totalMilesAccrued>
    </s:employeeFuelRecord>
</s:employeeFuelRecords>

উদাহরণ ২

  • ইনপুট: example02_input.xml
<s:FuelEvents xmlns:s="http://www.so2w.org">
    <s:FuelEvent employeeId="2413">
        <s:odometerReading>4089</s:odometerReading>
        <s:gallons>21.682</s:gallons>
        <s:gasPrice>3.46</s:gasPrice>
    </s:FuelEvent>
    <s:FuelEvent employeeId="3423">
        <s:odometerReading>6582</s:odometerReading>
        <s:gallons>15.248</s:gallons>
        <s:gasPrice>4.56</s:gasPrice>
    </s:FuelEvent>
    <s:FuelEvent employeeId="2413">
        <s:odometerReading>4127</s:odometerReading>
        <s:gallons>4.221</s:gallons>
        <s:gasPrice>3.40</s:gasPrice>
    </s:FuelEvent>
    <s:FuelEvent employeeId="2413">
        <s:odometerReading>4349</s:odometerReading>
        <s:gallons>11.192</s:gallons>
        <s:gasPrice>4.10</s:gasPrice>
    </s:FuelEvent>
    <s:FuelEvent employeeId="3423">
        <s:odometerReading>6767</s:odometerReading>
        <s:gallons>8.696</s:gallons>
        <s:gasPrice>3.34</s:gasPrice>
    </s:FuelEvent>
    <s:FuelEvent employeeId="2413">
        <s:odometerReading>4547</s:odometerReading>
        <s:gallons>9.197</s:gallons>
        <s:gasPrice>2.90</s:gasPrice>
    </s:FuelEvent>
</s:FuelEvents>
  • আউটপুট: example02_output.xml
<s:employeeFuelRecords xmlns:s="http://www.so2w.org">
    <s:employeeFuelRecord employeeId="2413">
        <s:gasFillUpCount>4</s:gasFillUpCount>
        <s:totalFuelCost>161.92962</s:totalFuelCost>
        <s:totalGallons>46.292</s:totalGallons>
        <s:totalMilesAccrued>458</s:totalMilesAccrued>
    </s:employeeFuelRecord>
    <s:employeeFuelRecord employeeId="3423">
        <s:gasFillUpCount>2</s:gasFillUpCount>
        <s:totalFuelCost>98.57552</s:totalFuelCost>
        <s:totalGallons>23.944</s:totalGallons>
        <s:totalMilesAccrued>185</s:totalMilesAccrued>
    </s:employeeFuelRecord>
</s:employeeFuelRecords>

ইঙ্গিত

GitHub-এর মাধ্যমে সম্পাদনা করুন লিংকটি একটি নতুন উইন্ডো বা ট্যাবে খোলে
Ballerina Exercism

XML ফুয়েল অ্যালাউয়েন্স শুরু করতে প্রস্তুত?

Exercism-এ সাইন আপ করুন, Ballerina ট্র্যাকের 60টি অনুশীলনী আর সত্যিকারের মানুষের মেন্টরিং দিয়ে শিখুন ও দক্ষ হয়ে উঠুন, সম্পূর্ণ বিনামূল্যে।