Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polymorphism.go #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions oops/polymorphism.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//polymorphism
package main
import "fmt"
type income interface {
calculate() int
source() string
}
type fixedbilling struct {
projectname string
biddedamount int
}
type timeandmaterial struct {
projectname string
noofhours int
hourlyrate int
}
func (fb fixedbilling) calculate() int {
return fb.biddedamount
}
func (fb fixedbilling) source() string {
return fb.projectname
}
func (tm timeandmaterial) calculate() int {
return tm.noofhours * tm.hourlyrate
}
func (tm timeandmaterial) source() string {
return tm.projectname
}
func calculatenetincome(ic [] income) {
var netincome int = 0
for _,income := range ic {
fmt.Printf("%s = %d" , income.source() , income.calculate())
netincome = income.calculate()
satyamuralidhar marked this conversation as resolved.
Show resolved Hide resolved
}
fmt.Printf("\n netincome of organization = %d",netincome)
}
func main() {
project1 := fixedbilling{projectname:"project1",biddedamount:8000}
project2 :=fixedbilling{projectname:"project2",biddedamount:5000}
project3 := timeandmaterial{projectname:"project3",noofhours:9,hourlyrate:1000}
totalgenerated := [] income{project1,project2,project3}
calculatenetincome(totalgenerated)

}