Click here to Skip to main content
15,886,110 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need suggestions for C# project Pin
harold aptroot29-Jul-13 3:13
harold aptroot29-Jul-13 3:13 
GeneralRe: Need suggestions for C# project Pin
Pete O'Hanlon29-Jul-13 3:17
mvePete O'Hanlon29-Jul-13 3:17 
GeneralRe: Need suggestions for C# project Pin
ZurdoDev29-Jul-13 4:41
professionalZurdoDev29-Jul-13 4:41 
AnswerRe: Need suggestions for C# project Pin
Eddy Vluggen29-Jul-13 3:20
professionalEddy Vluggen29-Jul-13 3:20 
AnswerRe: Need suggestions for C# project Pin
Amir Mohammad Nasrollahi29-Jul-13 4:19
professionalAmir Mohammad Nasrollahi29-Jul-13 4:19 
AnswerRe: Need suggestions for C# project Pin
AmitGajjar30-Jul-13 2:49
professionalAmitGajjar30-Jul-13 2:49 
AnswerRe: Need suggestions for C# project Pin
Alan Balkany30-Jul-13 4:35
Alan Balkany30-Jul-13 4:35 
QuestionDoes this code is object oriented or not ? Pin
stmk6929-Jul-13 1:05
stmk6929-Jul-13 1:05 
Hi all,
Please tell me if this code bellow object oriented or not. If it is not what changes that are needed to become an Object oriented?
Thank you.
Here is the code:

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<int> LstData; // Dynamic list to store the item value
Hashtable hTable; // Hashtable to use the store item name, itemValue pairs
///
/// Constructor method
///

/// <param name="Capacity" />
/// <param name="MenuNbr" />
public GrillMaster(int Capacity, string MenuNbr)
{
this.GrillCapacity = Capacity;
this.MenuNbr = MenuNbr;
this.LstData = new List<int>(); // 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

}
///
///
///

/// <param name="NbrItm" />
/// <param name="ItmVal" />
/// <param name="ItmName" />
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("svelkov@gmail.com", "Ycsu4"); 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();
}
}
}

modified 29-Jul-13 7:32am.

GeneralRe: Does this code is object oriented or not ? Pin
harold aptroot29-Jul-13 1:15
harold aptroot29-Jul-13 1:15 
GeneralRe: Does this code is object oriented or not ? Pin
ZurdoDev29-Jul-13 4:42
professionalZurdoDev29-Jul-13 4:42 
AnswerRe: Does this code is object oriented or not ? Pin
Eddy Vluggen29-Jul-13 9:05
professionalEddy Vluggen29-Jul-13 9:05 
QuestionC# Reflection Pin
KamranJavidSolutions29-Jul-13 0:25
KamranJavidSolutions29-Jul-13 0:25 
AnswerRe: C# Reflection Pin
Pete O'Hanlon29-Jul-13 1:54
mvePete O'Hanlon29-Jul-13 1:54 
GeneralRe: C# Reflection Pin
KamranJavidSolutions29-Jul-13 2:23
KamranJavidSolutions29-Jul-13 2:23 
AnswerRe: C# Reflection Pin
Manfred Rudolf Bihy29-Jul-13 2:30
professionalManfred Rudolf Bihy29-Jul-13 2:30 
QuestionError: External table is not in the expected format Pin
NarVish28-Jul-13 21:26
NarVish28-Jul-13 21:26 
AnswerRe: Error: External table is not in the expected format Pin
Richard MacCutchan28-Jul-13 22:29
mveRichard MacCutchan28-Jul-13 22:29 
GeneralRe: Error: External table is not in the expected format Pin
NarVish28-Jul-13 23:49
NarVish28-Jul-13 23:49 
GeneralRe: Error: External table is not in the expected format Pin
Richard MacCutchan29-Jul-13 0:01
mveRichard MacCutchan29-Jul-13 0:01 
GeneralRe: Error: External table is not in the expected format Pin
NarVish29-Jul-13 0:14
NarVish29-Jul-13 0:14 
GeneralRe: Error: External table is not in the expected format Pin
Richard MacCutchan29-Jul-13 0:20
mveRichard MacCutchan29-Jul-13 0:20 
GeneralRe: Error: External table is not in the expected format Pin
NarVish29-Jul-13 0:52
NarVish29-Jul-13 0:52 
QuestionScrollViewer adjusting HorizontalOffset in VirtualizingStackPanel Pin
Revolty28-Jul-13 3:39
Revolty28-Jul-13 3:39 
QuestionNeed help to use powershell script with two foreach in c# Pin
Member 981625927-Jul-13 19:37
Member 981625927-Jul-13 19:37 
AnswerRe: Need help to use powershell script with two foreach in c# Pin
Richard MacCutchan28-Jul-13 1:04
mveRichard MacCutchan28-Jul-13 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.