Photo AI

Complete the code as specified in QUESTION 3.1 for the Transaction_U object and QUESTION 3.2 for the Question3_U form class - NSC Information Technology - Question 3 - 2020 - Paper 1

Question icon

Question 3

Complete-the-code-as-specified-in-QUESTION-3.1-for-the-Transaction_U-object-and-QUESTION-3.2-for-the-Question3_U-form-class-NSC Information Technology-Question 3-2020-Paper 1.png

Complete the code as specified in QUESTION 3.1 for the Transaction_U object and QUESTION 3.2 for the Question3_U form class. 3.1 The incomplete object class (Transa... show full transcript

Worked Solution & Example Answer:Complete the code as specified in QUESTION 3.1 for the Transaction_U object and QUESTION 3.2 for the Question3_U form class - NSC Information Technology - Question 3 - 2020 - Paper 1

Step 1

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

96%

114 rated

Answer

class Transaction:
    def __init__(self, customerID, containerSize, storagePeriod):
        self.customerID = customerID
        self.containerSize = containerSize
        self.storagePeriod = storagePeriod
        self.amountPaid = 0.0

Step 2

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

99%

104 rated

Answer

    def getAmountPaid(self):
        return self.amountPaid

Step 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

    def updateAmountPaid(self, amount):
        self.amountPaid += amount

Step 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

    def calculateCost(self):
        if self.containerSize == 'S':
            initialCost = 1000.00
        elif self.containerSize == 'M':
            initialCost = 1750.00
        else:
            initialCost = 2500.00
        totalCost = (self.storagePeriod * initialCost)
        discount = 0.1 * (self.storagePeriod // 6)
        if discount > 0.5:
            discount = 0.5
        return totalCost * (1 - discount)

Step 5

Button [3.2.1] - Instantiate object

97%

117 rated

Answer

def instantiateTransaction():
    customerID = editCustomerID.text
    containerSize = listBoxContainerSize.selectedItem[0]
    storagePeriod = spinStoragePeriod.value
    objTransaction = Transaction(customerID, containerSize, storagePeriod)
    btnQ3_2_1.enabled = False

Step 6

Button [3.2.2 (a)] - Display amount due

97%

121 rated

Answer

def displayAmountDue():
    amountDue = objTransaction.calculateCost()
    pnlQ3_2_2.text = str(amountDue)

Step 7

Button [3.2.2 (b)] - Process payment

96%

114 rated

Answer

def processPayment():
    amountDue = objTransaction.calculateCost()
    pnlQ3_2_2.text = str(amountDue)

Step 8

Button [3.2.3] - View details

99%

104 rated

Answer

def viewDetails():
    details = f"Customer ID: {objTransaction.customerID}\nContainer Size: {objTransaction.containerSize}\nStorage Period: {objTransaction.storagePeriod}\nAmount Paid: {objTransaction.getAmountPaid()}"
    richEditBox.text = details

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

;