From 5c13112bbb56bbb96b1d015d1f6a26a9ec4199d3 Mon Sep 17 00:00:00 2001 From: satya <38804803+satyamuralidhar@users.noreply.github.com> Date: Sun, 19 Jul 2020 11:41:33 +0530 Subject: [PATCH 1/2] Create polymorphism.go --- oops/polymorphism.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 oops/polymorphism.go diff --git a/oops/polymorphism.go b/oops/polymorphism.go new file mode 100644 index 00000000..375b6a8c --- /dev/null +++ b/oops/polymorphism.go @@ -0,0 +1,43 @@ +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() + } + 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) + + } From ade29850701413e10c3e255058f8433b4d5dff3f Mon Sep 17 00:00:00 2001 From: satya <38804803+satyamuralidhar@users.noreply.github.com> Date: Sun, 19 Jul 2020 11:44:43 +0530 Subject: [PATCH 2/2] Update polymorphism.go --- oops/polymorphism.go | 1 + 1 file changed, 1 insertion(+) diff --git a/oops/polymorphism.go b/oops/polymorphism.go index 375b6a8c..62b09d03 100644 --- a/oops/polymorphism.go +++ b/oops/polymorphism.go @@ -1,3 +1,4 @@ +//polymorphism package main import "fmt" type income interface {