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

Recommended Answers

All 5 Replies

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?

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.

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

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).

thanks thines01 for helping me out..

Hello, akpage22. You can find some examples in this open source asp.net site. It is also a tool that helps you coding your asp.net applications in seconds! I think it is nice for any developers, because it is easy. Well, enjoy xD


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.