Photo AI

An import-export company rents out containers to customers who use it to store goods for a specific period of time - NSC Information Technology - Question 3 - 2020 - Paper 1

Question icon

Question 3

An-import-export-company-rents-out-containers-to-customers-who-use-it-to-store-goods-for-a-specific-period-of-time-NSC Information Technology-Question 3-2020-Paper 1.png

An import-export company rents out containers to customers who use it to store goods for a specific period of time. Transactions are created between the company and ... show full transcript

Worked Solution & Example Answer:An import-export company rents out containers to customers who use it to store goods for a specific period of time - NSC Information Technology - Question 3 - 2020 - Paper 1

Step 1

3.1.1 Write code for a constructor method that will receive the customer ID, container size and the storage period in months as parameters.

96%

114 rated

Answer

In the constructor method, we will accept customerID, containerSize, and storagePeriod as parameters. The AmountPaid will be initialized to zero.

constructor TTransaction.Create(iCustomerID: string; iContainerSize: char; iStoragePeriod: integer);
begin
  CustomerID := iCustomerID;
  ContainerSize := iContainerSize;
  StoragePeriod := iStoragePeriod;
  AmountPaid := 0;
end;

Step 2

3.1.2 Write code for an accessor method called getAmountPaid for the AmountPaid attribute.

99%

104 rated

Answer

The accessor method will return the current value of AmountPaid.

function TTransaction.getAmountPaid: real;
begin
  Result := AmountPaid;
end;

Step 3

3.1.3 Write code for a method called updateAmountPaid that will receive a value as a parameter and add the received value to the AmountPaid attribute.

96%

101 rated

Answer

We will define a method to update the AmountPaid by adding the provided amount.

procedure TTransaction.updateAmountPaid(amount: real);
begin
  AmountPaid := AmountPaid + amount;
end;

Step 4

3.1.4 Write code for a method called calculateCost that will use the Transaction object's attributes to calculate and return the cost of renting the container.

98%

120 rated

Answer

This method calculates the cost based on ContainerSize and StoragePeriod, applying discounts as necessary.

function TTransaction.calculateCost: real;
var
  initialCost: real;
  discount: real;
begin
  if ContainerSize = 'S' then
    initialCost := 1000.00
  else if ContainerSize = 'M' then
    initialCost := 1750.00
  else
    initialCost := 2500.00;

  discount := 0.10 * (StoragePeriod div 6);
  if discount > 0.5 then
    discount := 0.5;

  Result := StoragePeriod * initialCost * (1 - discount);
end;

Step 5

3.1.5 Write code to complete the toString method to return the attributes of the Transaction object in a specific format.

97%

117 rated

Answer

The toString method will format the output of Transaction attributes.

function TTransaction.toString: string;
begin
  Result := 'Customer ID: ' + CustomerID + '\n' +
            'Container size: ' + ContainerSize + '\n' +
            'Storage period (months): ' + IntToStr(StoragePeriod) + '\n' +
            'Amount paid: ' + FloatToStr(AmountPaid);
end;

Step 6

3.2.1 Button [3.2.1] - Instantiate object

97%

121 rated

Answer

In the event handler for the button, we extract the needed values and create a new Transaction object.

procedure TForm.MainButtonClick(Sender: TObject);
var
  customerID: string;
  size: char;
  months: integer;
begin
  customerID := editQ3_2_1.Text;
  size := lstQ3_2_1.Items[lstQ3_2_1.ItemIndex][1];
  months := spinQ3_2_1.Value;

  objTransaction := TTransaction.Create(customerID, size, months);
  btnQ3_2_1.Enabled := False;
end;

Step 7

3.2.2 (a) Button [3.2.2 (a)] - Display amount due!

96%

114 rated

Answer

To display the amount due, we call the calculateCost method and then show the result in the specified panel.

procedure TForm.DisplayAmountDue;
begin
  pnlQ3_2_2.Caption := FloatToStr(objTransaction.calculateCost);
end;

Step 8

3.2.2 (b) Button [3.2.2 (b)] - Process payment

99%

104 rated

Answer

This procedure retrieves the amount from the edit box, updates the AmountPaid, and displays the updated amount.

procedure TForm.ProcessPayment;
var
  amountPaid: real;
begin
  amountPaid := StrToFloat(editQ3_2_2.Text);
  objTransaction.updateAmountPaid(amountPaid);
  pnlQ3_2_2.Caption := FloatToStr(objTransaction.getAmountPaid);
end;

Step 9

3.2.3 Button [3.2.3] - View details

96%

101 rated

Answer

We clear the rich edit component and then display the attributes of the Transaction object clearly.

procedure TForm.ViewTransactionDetails;
begin
  richEdit.Clear;
  richEdit.Lines.Add(objTransaction.toString);
end;

Join the NSC students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;