Swift POP Interest Calculation

We have give task for Swift POP Interest Calculation as -

---Un editable Code---
import Foundation
protocol Interest{
    var p:Double {get}
    var t:Int {get}
    var r:Double {get}
    var interest:Double {get}
    var amount:Double {get}
}
---END Un editable Code---
---Editable Code---
class BaseInterest: Interest {
        var p:Double
        var t:Int 
        var r:Double 
        var interest:Double 
        var amount:Double 
        init(_ p:Double, _ t:Int, _ r:Double, _ interest:Double _ amount:Double) {
            self.p = p;
            self.t  = t;
            self.r  = r;
            self.interest  = interest;
            self.amount  = amount;
        }
    }

class Compound:BaseInterest{
    var n1 : Int = 0
    init(p1 p:Double,t1 t:Int,r1 r:Double, n1 n: Double) {
            n1 = n
            super.init(p, t, r)
        }
    let CIA = p1(1 + r/n1)^(n1*t1);
    print(CIA)
}
class Simple:BaseInterest{
    init(p1 p:Double,t1 t:Int,r1 r:Double) {
            n1 = n
            super.init(p, t, r)
        }
    let SI = p1 * t1 * r1;
    print(SI)
}
---End editable Code---
---Un editable Code---
let stdout = ProcessInfo.processInfo.environment["OUTPUT_PATH"]!
FileManager.default.createFile(atPath: stdout, contents: nil, attributes: nil)
let fileHandle = FileHandle(forWritingAtPath: stdout)!

guard let p = Double((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!)
else { fatalError("Bad input") }
guard let t = Int((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!)
else { fatalError("Bad input") }
guard let r = Double((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!)
else { fatalError("Bad input") }
guard let n = Int((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!)
else { fatalError("Bad input") }

var interest:Interest = Simple(p:p,t:t,r:r)
fileHandle.write(String(interest.interest).data(using: .utf8)!)
fileHandle.write("\n".data(using: .utf8)!)
fileHandle.write(String(interest.amount).data(using: .utf8)!)
fileHandle.write("\n".data(using: .utf8)!)

interest = Compound(p:p,t:t,r:r,n:n)
fileHandle.write(String(interest.interest).data(using: .utf8)!)
fileHandle.write("\n".data(using: .utf8)!)
fileHandle.write(String(interest.amount).data(using: .utf8)!)
fileHandle.write("\n".data(using: .utf8)!)
---END Un editable Code---

When we running it then we are getting compilation error.

1 Like

This post was flagged by the community and is temporarily hidden.

please help us

Terms of Service

Privacy Policy

Cookie Policy