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 3
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
In the constructor method, we will accept customerID, containerSize, and storagePeriod as parameters. The AmountPaid will be initialized to zero.
3.1.2 Write code for an accessor method called getAmountPaid for the AmountPaid attribute.
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
In the event handler for the button, we extract the needed values and create a new Transaction object.