Click to See Complete Forum and Search --> : another assignment going crazy...


wigga
June 13th, 2009, 08:44 AM
hi,

the point of this assignment is to make 2 classes, on to check for a "high street" and a "low street" there are 5 dices, the high street is 23456 the low street is 12345. i cannot use an array in one of the two classes. in the other i can use one so i use a sorted array. but i am really stuck and i am getting a **** headache. can anyone give me atleast a hint or tip get me in the right direction or just tell me how todo it so i can finish this stupid assignment and work on my own C++ projects. thanks.

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace w1
{
public partial class Form1 : Form
{
class Dobbel
{
public uint[] stenen = new uint[5];

public Dobbel()
{
Thread.Sleep(1000);
Random s = new Random();
for(int i = 0; i < 5; ++i)
{
Thread.Sleep(1000);
stenen[i] = (uint)s.Next(1, 6);
}
}
};

class GroteStraat
{
public bool b;

GroteStraat(Dobbel d)
{
ArrayList s = (ArrayList)d.stenen;
s.Sort();
foreach (uint i in s)
{
}
}
};

public Form1()
{
InitializeComponent();
}

private void btnDobbel_Click(object sender, EventArgs e)
{
Dobbel d1 = new Dobbel();
picD1.Image = Properties.Resources.Dobbel(d1.stenen[0]);
picD2.Image = Properties.Resources.Dobbel(d1.stenen[1]);
picD3.Image = Properties.Resources.Dobbel(d1.stenen[2]);
picD4.Image = Properties.Resources.Dobbel(d1.stenen[3]);
picD5.Image = Properties.Resources.Dobbel(d1.stenen[4]);
Dobbel d2 = new Dobbel();
picD6.Image = Properties.Resources.Dobbel(d2.stenen[0]);
picD7.Image = Properties.Resources.Dobbel(d2.stenen[1]);
picD8.Image = Properties.Resources.Dobbel(d2.stenen[2]);
picD9.Image = Properties.Resources.Dobbel(d2.stenen[3]);
picD10.Image = Properties.Resources.Dobbel(d2.stenen[4]);
}

}
}

Laivindur
June 13th, 2009, 09:57 AM
Can't you just compare every item in your list to the values you are looking for? And for the class where you cant use an array, just specify the items as normal integers. There are only 5 :)

wigga
June 13th, 2009, 10:00 AM
yes i could do that let met redo the code.. and come back here

wigga
June 13th, 2009, 10:11 AM
okay here i am back.

i am getting errors that the class does not take 1 argument :/ and the other class does not take 5 arguments... :/

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace w1
{
public partial class Form1 : Form
{
class Dobbel
{
public uint[] stenen = new uint[5];

public Dobbel()
{
Thread.Sleep(1000);
Random s = new Random();
for(int i = 0; i < 5; ++i)
{
Thread.Sleep(1000);
stenen[i] = (uint)s.Next(1, 6);
}
}
};

class GroteStraat
{
public bool b;

GroteStraat(Dobbel d)
{
uint j = 2;
foreach (uint i in s)
{
if (i != j)
{
b = false;
return;
}
++j;
}
b = true;
}
};

class KleineStraat
{
public bool b;

KleineStraat(uint d1, uint d2, uint d3, uint d4, uint d5)
{
b = d1 == 1 && d2 == 2 && d3 == 3 && d4 == 4 && d5 == 5;
}
};

public Form1()
{
InitializeComponent();
}

private void btnDobbel_Click(object sender, EventArgs e)
{
Dobbel d1 = new Dobbel();
picD1.Image = Properties.Resources.Dobbel(d1.stenen[0]);
picD2.Image = Properties.Resources.Dobbel(d1.stenen[1]);
picD3.Image = Properties.Resources.Dobbel(d1.stenen[2]);
picD4.Image = Properties.Resources.Dobbel(d1.stenen[3]);
picD5.Image = Properties.Resources.Dobbel(d1.stenen[4]);
if (new GroteStraat(d1).b)
lblS1.Text = "Grote Straat";
else if (new KleineStraat(d2.stenen[0], d2.stenen[1], d2.stenen[2], d2.stenen[3], d2.stenen[4]).b)
lblS1.Text = "Kleine Straat";
else
lblS1.Text = "Nix";
Dobbel d2 = new Dobbel();
picD6.Image = Properties.Resources.Dobbel(d2.stenen[0]);
picD7.Image = Properties.Resources.Dobbel(d2.stenen[1]);
picD8.Image = Properties.Resources.Dobbel(d2.stenen[2]);
picD9.Image = Properties.Resources.Dobbel(d2.stenen[3]);
picD10.Image = Properties.Resources.Dobbel(d2.stenen[4]);
if (new GroteStraat(d1).b)
lblS2.Text = "Grote Straat";
else if (new KleineStraat(d2.stenen[0], d2.stenen[1], d2.stenen[2], d2.stenen[3], d2.stenen[4]).b)
lblS2.Text = "Kleine Straat";
else
lblS2.Text = "Nix";
}

}
}

JonnyPoet
June 14th, 2009, 04:08 AM
Excude me but what is this ?


class KleineStraat
{
public bool b;

KleineStraat(uint d1, uint d2, uint d3, uint d4, uint d5)
{
b = d1 == 1 && d2 == 2 && d3 == 3 && d4 == 4 && d5 == 5;
}
};

You are simple comparing 5 integers with fixed numbers so in any case if you would not have 1,2,3,4,5 as an input it will result in b= false ?
Whats the sense behind all that.
There is a basic problem too. If you want to get good advice please use english terms for all items in your program. 'dutch' terms are difficuold to think with for most of the people here. So the standard rule is code it using english terms and use terms which are 'talking' meaning that they express what they are used for. I cannot find out what you are wanting to do. Whats this array ? Why are you comparing in an constructor. Why are you using a class when you don't keep the simplest rules of classes to have no public fielsa in that class.
BTW the classes are totally useless, you can simple replace them by methods

class GroteStraat
{
public bool b;

GroteStraat(Dobbel d)
{
uint j = 2;
foreach (uint i in s)
{
if (i != j)
{
b = false;
return;
}
++j;
}
b = true;
}
};

This simple cannot compile because whats s in your class ? And why a semicolon after a class definition? But as already told your classes are baically nothing then a method definition. Who has learned you to built classes like that?

wigga
June 14th, 2009, 09:33 AM
oops yeah sorry there are a few mistakes. I have worked it out now. s should have been d.

yeah usually i make my terms in english.
and my programming style comes from C++ sorry about that.

JonnyPoet
June 14th, 2009, 10:12 AM
oops yeah sorry there are a few mistakes. I have worked it out now. s should have been d.

yeah usually i make my terms in english.
and my programming style comes from C++ sorry about that.Hmmm this still doesn't explain why you have public fields as members of your classes. Even in C++ this wasn't good coding style and what should all that be. If I'm your teacher this, even if it will work in the end would be at least a bad result, because you are simple breaking all rules of a class. Class means encapsulation. You need to have private fields and properties. There is a list of No-Go's in the web and this really is a major heavy outpoint.
To your program: It seems me to talk about mainstreets and small streets but whts this array of uint where you express a 5 digit number by an array of digits. So I would relly want to know whats by definition in your case is a mainstreet and a smallstreet and why you are checking each digit seperate instad of simple comparing the value?

if (number > 12345 ){
// mainstreet
}else{
// small street
}
So whats the whole assignment, what are the images for

wigga
June 15th, 2009, 03:26 AM
because they are dices.

and its not a bad coding style to me, nothing wrong with it

JonnyPoet
June 15th, 2009, 04:34 AM
...and its not a bad coding style to me, nothing wrong with itThere are always different ways to handle something in life. Ignorance per sure is always the badest. :thumbd:

darwen
June 15th, 2009, 08:30 AM
...and its not a bad coding style to me, nothing wrong with it


Well actually there is a lot wrong with it. It breaks encapsulation for one. When you get out into the 'real' world, you'll find that public member variables can cause you infinite headaches in commercial systems where you are not the only developer.

But also :


if (new KleineStraat(d2.stenen[0], d2.stenen[1], d2.stenen[2], d2.stenen[3], d2.stenen[4]).b)


Here you are instansiating an object just to obtain a boolean value. There are a number of problems with this :

1. Unnecessary memory allocation.
2. Not easily readable code.

How about having a street test static class e.g.


static class StreetTester
{
static public bool IsKleineStraat(uint d1, uint d2, uint d3, uint d4, uint d5)
{
return d1 == 1 && d2 == 2 && d3 == 3 && d4 == 4 && d5 == 5;
}
}


Then you could do


if (StreetTester.IsKleineStraat(...))
{
}


And as a final note, you shouldn't have your classes nested in the form. They should be seperate and outside the form to promote reuse. At the present time all your code HAS to be in the form as no code outside the form can see your classes.

It is widely regarded as good practice to limit the amount of code inside the UI classes and to have the 'business logic' or the 'meat' of the application elsewhere.

Again this promotes reuse, unit testing etc etc.

All the improvements I've mentioned apply equally to C++ as to C# : they are part of the object orientation paradigm.

And I think you'll find once you've seperated your code and and arranged it logically with meaningful names for functions/variables you'll be in a much better position to find out why it isn't working.

Darwen.

wigga
June 17th, 2009, 06:50 AM
i ama familiar with all things pointed out.

but its just an assignment! no fuzz.

JonnyPoet
June 17th, 2009, 09:58 AM
i ama familiar with all things pointed out.

but its just an assignment! no fuzz.Thats why I said you are ignorant. Assignments are preparing people for real life. An assignment has to be the same way then you would work later in a firm.

Bad habits are easily created, but difficult to get rid off. You coding style, but it seems me your whole intention to learn and how to do work is horrible. :rolleyes:

wigga
June 17th, 2009, 11:00 AM
well i dont have time, i got mor eassignments i need to concentrate on. so i just do something simple and quick in 10 minutes and pass it in, ofcourse i wont code this way in a real aPP

BigEd781
June 17th, 2009, 12:18 PM
well i dont have time, i got mor eassignments i need to concentrate on. so i just do something simple and quick in 10 minutes and pass it in, ofcourse i wont code this way in a real aPP

In the real world, you will always be pressed for time, but that is no reason to be sloppy.

wigga
June 17th, 2009, 05:04 PM
and i dont get payed todo this. i just do qhatever is the requirement cause i want to pass school.
i dont have time to perfect my code like did when i was freelancing.

now take that and stfu pls cus u wont win. good day

BigEd781
June 17th, 2009, 05:14 PM
OK, please let me know when you get a job so I can avoid buying software that you are working on.

darwen
June 18th, 2009, 04:32 AM
i just do qhatever is the requirement cause i want to pass school.
i dont have time to perfect my code like did when i was freelancing.


Are you growing younger every year, like Jason Button ?

Most people go to school and then freelance - or rather go to school, go to university, work in the industry for a number of years and then freelance.

You seem to be doing things in the wrong order...

At any rate you should be perfecting your code now, the more you get used to good practice the more like second nature it becomes.

That's what I did and I find these days that I don't have to go back and refactor every line of code I write.

I still have to go back and refactor sometimes, but as time goes on the amount of code I have to refactor gets less and less. That's what learning's all about and to me it's one of the joys of working in the programming industry - you can always improve nomatter how long you've been working in the field.

Darwen.

Brad Jones
June 18th, 2009, 07:58 AM
now take that and stfu pls cus u wont win. good day

I *will* win, so please heed my words below....

Thats why I said you are ignorant.


How people respond towards others is regulated by the acceptable usage policy on this forum. Please stop the negativity towards each other.

Additionally, profanity even when filtered like the first post of this thread, is not allowed on this forum. Additionally, telling someone to stfu is also crossing the line of what is acceptable on this forum.

Please refrain from personal attacks or comments going forward or you'll be asked to take it outside. :)

Thanks.

Also to doing sloppy assignments, we have to hope that the professor / teacher will deduct the appropriate amount of points for doing bad things in code. As to being at school to get a grade rather than to learn, that is a personal choice. I personally think that is a waste of a lot of money for a grade rather than an education.

Let's get this thread back to answering a homework asisgnment...... :rolleyes:

Brad!

Brad!

wigga
June 18th, 2009, 08:36 AM
I *will* win, so please heed my words below....

ouch so true!

Also to doing sloppy assignments, we have to hope that the professor / teacher will deduct the appropriate amount of points for doing bad things in code. As to being at school to get a grade rather than to learn, that is a personal choice. I personally think that is a waste of a lot of money for a grade rather than an education.

okay first of all i dont need to learn much anymore , i have been freelancing enough.
as i said they give alot of assignments C# is not my only subject. its not my fault they give to much assignments. Yes i do prefer education over a grade. But wasting another year is not an option for me. All the assignments are easy for me allready and im happy some subjects are already off my list cause i was too good at them. Andd still i am so busy. As far the code being sloppy i could give a **** cause its not a real app and i dint want to spend to much time thinking about it. So if the teacher doesnt like it i will do it his way and just be finished with it.
And if poeple dont agree and keep bashing my code is sloppy they need to get off my back cause they arent helping at all, its them who start being negative towars me

Brad Jones
June 18th, 2009, 08:56 AM
Thread closed.