using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace GrillMaster
{
///
/// This class is main class.
///
public class GrillMaster
{
int GrillCapacity;
string MenuNbr;
int k;
int[] BestFit;
List LstData; // Dynamic list to store the item value
Hashtable hTable; // Hashtable to use the store item name, itemValue pairs
///
/// Constructor method
///
///
///
public GrillMaster(int Capacity, string MenuNbr)
{
this.GrillCapacity = Capacity;
this.MenuNbr = MenuNbr;
this.LstData = new List(); // Dynamic list to store the item value
this.BestFit = new int[100];
this.hTable = new Hashtable(); // Hashtable to use the store item name, itemValue pairs
}
///
///
///
///
///
///
public void FillList(int NbrItm, int ItmVal, string ItmName)
{
for (int i = 1; i <= NbrItm; i++)
{
LstData.Add(ItmVal); // fill in the list data with the item value
}
if (!(hTable.ContainsKey(ItmName)))
{
hTable.Add(ItmName,ItmVal); // if HashTable not contains the current item then add it.
}
}
///
///
///
public void ClearList()
{
this.LstData.Clear();
}
public void NumberOfRoundsBestFit()
{
int m = 0;
bool bOK = true;
k = 0;
LstData.Sort(); //Sort the data
LstData.Reverse(); // Sort the data in descending order
BestFit[k] = GrillCapacity;
foreach (var elm in LstData)
{
bOK = true;
for (int m1 = 0; m1 <= m; m1++)
{
if (elm <= BestFit[m1])
{
BestFit[m1] -= elm;
bOK = false; //if find correct empty Grill set variable to false
break;
}
}
if (bOK)
{
k++; //increase the rounds
BestFit[k] = GrillCapacity; // set the initial capacity of the grill
BestFit[k] -= elm; //Decrease the capacity of the grill
}
m = k;
}
}
///
///
///
public void NumberOfRounds()
{
int Capacity = GrillCapacity; // save the capacity of Grill
k = 0;
LstData.Sort(); //Sort the data
LstData.Reverse(); // Sort the data in descending order
foreach (var elm in LstData)
{
if (elm <= Capacity && elm <= GrillCapacity)
Capacity -= elm; //Decrease the capacity of the grill
else
{
k++; //increase the rounds
Capacity = GrillCapacity; // set the initial capacity of the grill
Capacity -= elm; //Decrease the capacity of the grill
}
}
foreach (DictionaryEntry entry in hTable)
{
Console.WriteLine("{0}, {1} ", entry.Key, entry.Value); //display on the console key and value of the HashTable
}
}
///
///
///
public void PrintData()
{
Console.WriteLine("Menu "+ this.MenuNbr + ": "+ (k + 1) + " rounds.");
}
}
///
///
///
class Program
{
static void Main(string[] args)
{
int GrilDim = 600; //Der Grill misst 20cm x 30cm
string MenuName = "";
int[] Items = new int[] { 100, 200, 300, 400, 200, 100 };
string[] ItemsName = new string[] { "Fleisch1", "Fleisch2", "Fleisch3", "Fleisch4", "Fleisch2", "Fleisch1" };
/* Uri serviceUri = new Uri("http://grillassessment.cloudapp.net/GrillMenuService.svc");
var serviceCreds = new NetworkCredential("[email protected]", "pasw"); var cache = new CredentialCache(); cache.Add(serviceUri, "Basic", serviceCreds);
var service = new GrillMenu.GrillMenuContext(serviceUri)
{ Credentials = cache };
foreach (var grillMenu in service.GrillMenus.Expand(g => g.GrillMenuItemQuantity))
{
Console.WriteLine("Menu: {0}", grillMenu.Name);
MenuName = grillMenu.Name;
GrillMaster TestGrill = new GrillMaster(GrilDim, MenuName);
foreach (var grillMenuItemQuantity in grillMenu.GrillMenuItemQuantity)
{ service.LoadProperty(grillMenuItemQuantity, "GrillMenuItem");
TestGrill.FillList(1, grillMenuItemQuantity.Quantity, grillMenuItemQuantity.GrillMenuItem.Name);
Console.WriteLine("{0} x {1}", grillMenuItemQuantity.Quantity, grillMenuItemQuantity.GrillMenuItem.Name);
}
*/
GrillMaster TestGrill = new GrillMaster(GrilDim, MenuName);
for(int i =0; i < Items.Length; i++)
{
TestGrill.FillList(1, Items[i],ItemsName[i]);
}
TestGrill.NumberOfRounds();
TestGrill.PrintData();
TestGrill.ClearList(); // Clear the list , and prepare for the next menu!!!
Console.WriteLine();
//}
Console.ReadLine();
}
}
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Jul 29, 2013, 9:42 AM
Objects
Classes
Encapsulation
Interfaces
Polymorphism
Inheritance
Your program contains Objects, Classes and Encapsulation. Therefore it is an object oriented program.
Ruchi HPosted Jul 29, 2013, 7:34 AM
Your code is definitely object oriented. You are creating object for different classes like GrillMenu, GrillMaster.