Resolved OOP project help and info needed

Xandro_2000

New member
Joined
Dec 29, 2020
Messages
2
Programming Experience
Beginner
Hello

I got an mock exam to practice, my real exam is in two weeks. I'm studying to become a teacher (this is an extra class I took) but with corona I had so many things to do including internship, etc. So I really I did not have a lot of time to practice C sharp. I only understand the basics, for this mock exam (check under this paragraph) I only created the classes (barrel, normalBarrel, reserveBarrel and Program itself). I have no clue how to start, I know I first have start with making all the barrels (automatic), then the consumption, refill, etc. Can someone explain me what to do or write me an example code. Thanks!


Mock exam
A beverage consumer wants a program to monitor his barrels. He can purchase two different products, product A and product B. The program requires the following input:
How many Barrels of product A do you want?
3
How many Barrels of product B do you want?
1
Done
You can consume product A and B.
The correct amount of barrel objects is automatically created with this data. For each product where barrel objects are created, with a capacity and content (expressed in liters) for each product, a spare barrel is also created with a capacity of double the total capacity of all barrels of that product together.
The beverage consumer can consume these products (expressed in liters), whereby the content (expressed in liters) of the consumed barrel object decreases with the amount of liters consumed.
When the content of a barrel object is less than 50% of its capacity, the content of this barrel object is supplemented with the spare barrel of that product.
page1image25182208



Each barrel has an alarm function that is checked after each consume or fill. The alarm can print one of the following messages:
  • - I am full
  • - I am empty
  • - I need a refill
    A reserve barrel has a “show content” method that displays the current content of the reserve barrel. This method is called every time after consuming from the reserve barrel. The reserve barrel also has an alarm with the following functionality:
- I am empty
And last but not least. I make dummy proof! You cannot consume more than the content of the barrel. You cannot fill the barrel more than the capacity of the barrel. If you do one of these options, the functions “Fill” and “Consume” will automatically take the respective minimum and maximum.
Each barrel object has the following attributes and methods:
  • - name or ID
  • - type (product A or B)
  • - capacity (expressed in liters)
  • - content (expressed in liters)
    Each spare barrel object has the following attributes and methods:
  • - name or ID
  • - type (product A or B)
  • - capacity (expressed in liters)
  • - content (expressed in liters)
- fill (expressed in liters)
- consume (expressed in liters) - alarm → I am full
→ I am empty → I need a refill
- showContent (expressed in liters) - consume (expressed in liters)
- alarm → I am empty

Write your own main () in which you demonstrate that all these functionalities work. You will be assessed on the following matters:
 
Can someone explain me what to do or write me an example code.
Unfortunately, we are neither a code writing service nor a tutorial service. We can help you with your existing code and if you tell us what problems your are running into, but you need to show us your code.

In general, the approach to programming is to breakup big problems into smaller problems, and then tackle the smaller problems. Your mock exam may look overwhelming because of the level of detail described in the interactions, but if you tackle each small action and attribute at a time, it will all be doable.
 
Hello

I've little to no knowledge and I'm stuck at an exercise. Can someone please give me info on how to go forward. Code is under the exercise and downloadable as zip.
Exercise:

A beverage consumer wants a program to monitor his barrels. He can purchase two different products, product A and product B. The program requires the following input:
How many Barrels of product A do you want?
3
How many Barrels of product B do you want?
1
Done
You can consume product A and B.

The correct amount of barrel objects is automatically created with this data. For each product where barrel objects are created, with a capacity and content (expressed in liters) for each product, a spare barrel is also created with a capacity of double the total capacity of all barrels of that product together.

The beverage consumer can consume these products (expressed in liters), whereby the content (expressed in liters) of the consumed barrel object decreases with the amount of liters consumed.

When the content of a barrel object is less than 50% of its capacity, the content of this barrel object is supplemented with the spare barrel of that product.

Each barrel has an alarm function that is checked after each consume or fill. The alarm can print one of the following messages:
- I am full
- I am empty
- I need a refill

A reserve barrel has a “show content” method that displays the current content of the reserve barrel. This method is called every time after consuming from the reserve barrel. The reserve barrel also has an alarm with the following functionality:
- I am empty

And last but not least. I make dummy proof! You cannot consume more than the content of the barrel. You cannot fill the barrel more than the capacity of the barrel. If you do one of these options, the functions “Fill” and “Consume” will automatically take the respective minimum and maximum.

Each barrel object has the following attributes and methods:
- name or ID
- type (product A or B)
- capacity (expressed in liters)
- content (expressed in liters)

Each spare barrel object has the following attributes and methods:
- name or ID
- type (product A or B)
- capacity (expressed in liters)
- content (expressed in liters)
- fill (expressed in liters)
- consume (expressed in liters)
- alarm → I am full → I am empty → I need a refill
- showContent (expressed in liters) - consume (expressed in liters)
- alarm → I am empty

Write your own main () in which you demonstrate that all these functionalities work. You will be assessed on the following matters:


Code:

C#:
using System;

namespace examenOpdracht
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int AskBarrels(string prod)
            {
                Console.Write("How many barrels '" + prod + "' do you want? \n");
                string inputaantal = Console.ReadLine();
                int aantal;
                bool success1 = int.TryParse(inputaantal, out aantal);
                while (!success1)
                {
                    Console.WriteLine("Invalid Input. Try again...");
                    Console.Write("Please enter a number: ");
                    inputaantal = Console.ReadLine();
                    success1 = int.TryParse(inputaantal, out aantal);
                }
                return aantal;
            }

            int aantalcola = AskBarrels("cola");
            int aantalfanta = AskBarrels("fanta");
            int totalaantal = aantalcola + aantalfanta;

            var ProdReserve = new ReserveBarrel[2];
            ProdReserve[0] = new ReserveBarrel("cola");
            ProdReserve[1] = new ReserveBarrel("fanta");

        }
    }
}






using System;
namespace examenOpdracht
{
    public class Barrel
    {
        public string Id;
        public string Type; //Cola of Fanta
        public double Capacity = 100; //Liter
        public double Content = 100; //Liter

        public void Consume(double n)
        {

        }


    }
}   






using System;
using System.Collections.Generic;

namespace examenOpdracht
{
    public class NormalBarrel : Barrel
    {

        public void Fill(double n)
        {

        }

        public void Alarm()
        {

        }

        public void normalBarrel(string prodID, string prodType)
        {
        Id = prodID;
        Type = prodType;
        Capacity = 100;
        Content = 100;

            foreach (ReserveBarrel Resv in ProdReserve)
            {
                if (Resv.Type == prodType)
                {
                Resv.Capacity = Resv.Capacity + Capacity;
                }
            }
        }
    }
}






using System;
namespace examenOpdracht
{
    public class ReserveBarrel : Barrel
    {

        public void ShowContent(double n)
        {

        }

        public void Alarm()
        {

        }

        public void reserveBarrel(string prodID, string prodType)  //constructor
        {
        Id = prodID;
        Type = prodType;
        Capacity = 0;
        Content = 0;
        }

    }
}
 

Attachments

  • Code.zip
    16.5 KB · Views: 21
Last edited:
This is the same topic as your post over a week ago. Merging threads...
 
Back
Top Bottom