Photo AI

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 icon

Question 3

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.png

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

Answer

The constructor for the TTransaction class can be defined as follows:

public TTransaction(string customerID, string containerSize, int storagePeriod)
{
    this.customerID = customerID;
    this.containerSize = containerSize;
    this.storagePeriod = storagePeriod;
    this.amountPaid = 0;
}

Step 2

1.2 Write code for an accessor method called getAmountPaid for the amountPaid attribute.

99%

104 rated

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

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

Answer

The calculateCost method can be written as follows:

public double CalculateCost()
{
    double initialCost;
    if (this.containerSize == "S")
        initialCost = 750.00;
    else if (this.containerSize == "M")
        initialCost = 1750.00;
    else
        initialCost = 2500.00;

    double totalCost = initialCost * this.storagePeriod;
    double discount = Math.Floor(this.storagePeriod / 6) * 0.10;
    if (discount > 0.50) discount = 0.50;

    totalCost -= totalCost * discount;
    return totalCost;
}

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

;