Hi friends

I am learning C# language online and came across this question

Code Exercise: Cola Machine

Please use the language of your choice to model a simple cola machine.

Within the cola machine, please create classes for the Drinks, Inventory and Bank.

The Inventory should hold multiple types of drinks and allow for drinks of varying prices to be bought.

The Bank should have a certain amount of money and be updated by the price of a cola when bought by a consumer.


Can anyone give me examples of the above excercies....thank you in advance

How can an online C# training exercise allow you to use any language?
...or is it:
This is homework and you're learning C# online to solve it?

...doesn't matter as I will ask the same question:
Which part is giving you a problem?

Samples?
Yes, there are multitudes of samples of class creation on this site.
If you have a particular question about a command or some syntax or a better way of doing something, please ask.

Edited 4 Years Ago by thines01: clarity

thanks thines01 for you response.. the banking class is where i am having problems...and its not home work... that tutorial has other languages as well and uses the same exercise...

Well, it (the bank) will just be a container of a value (and how to access it).

public class CBank
   {
      public double dblValue { get; private set; }
      public CBank(double dblValue)
      {
         this.dblValue = dblValue;
      }

      public void Add(double dbl)
      {
         dblValue += dbl;
      }

      public void Subtract(double dbl)
      {
         if (dblValue >= dbl)
         {
            dblValue -= dbl;
         }
      }
   }

...with a test

CBank bank = new CBank(1.23);//initial value
         Console.WriteLine(bank.dblValue);
         bank.Add(2.34);
         Console.WriteLine(bank.dblValue);

What will actually happen is when a soft-drink is purchased, an amount will be added to the existing bank amount. Change will be given based on the type of currency issued by the user (and based on availability of currency).

This article has been dead for over six months. Start a new discussion instead.