An import-export company rents out containers to customers who use 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 to store goods for a specific period of time. Transactions are created between the company and the... show full transcript
Worked Solution & Example Answer:An import-export company rents out containers to customers who use to store goods for a specific period of time - NSC Information Technology - Question 3 - 2020 - Paper 1
Step 1
1.1 Write code for a constructor method that will receive the following 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
The constructor for the TTransaction class can be defined as follows:
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 for getting the amount paid can be implemented as follows:
public double GetAmountPaid()
{
return this.amountPaid;
}
Step 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
The method for updating the amount paid can be defined like this:
public void UpdateAmountPaid(double amount)
{
this.amountPaid += amount;
}
Step 4
1.4 Write code for a method called calculateCost that will use the Transaction objects’ 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
The calculateCost method can be written as follows: