DEV Community

Discussion on: Comparing Code: Ruby, JavaScript, and Java Walk Into a Bar...

Collapse
akdeberg profile image
Anik Khan

Emily, you remind me of a wonderful period of my life with C#. Never in my life, I thought even once that I would learn C#. Yet in 2017, when I was introduced to the language, I knew it is something that I am gonna adore a lot. Over the years my love for it only increases. It's so expressive, elegant; you can relate as it's pretty close to java.
I committed so much so that I looked down other languages like js, PHP. Ignoring js wasn't a good decision, btw.
So this year, I am truly devoted to Js. My path is kinda opposite of yours as you can see. Yet I can feel the excitement of the journey.
Wish you all the best along the way.
Ohh, I couldn't help but writing the code in C#( love of my life 😍):

//Both classes are under the same namespace

class Program
    {
        static void Main(string[] args)
        {
            var emilysCoffeMaker = new CoffeMaker(5);
            Console.WriteLine(emilysCoffeMaker.MakeCoffee());
        }
    }


class CoffeMaker
    {
        //this public property automatically will create a private field _coffepercup behind the scene 
        public int CoffePerCup
        {
            get
            {
                return 20;
            }
        }

        //this public property automatically will create a private field _waterpercup behind the scene 
        public int WaterPerCup
        {
            get
            {
                return 14;
            }
        }

        //public property to create setter
        public int CupsToMake { get; set; }

        public CoffeMaker(int cupsToMake)
        {
            this.CupsToMake = cupsToMake;
        }

        //method to make coffee
        public string MakeCoffee()
        {
            return $"You will need {WaterPerCup * CupsToMake} oz. of water and {CoffePerCup * CupsToMake} grams of coffee beans to make {CupsToMake} cups of coffee.";
        }
    }