|
-
June 13th, 2009, 08:44 AM
#1
another assignment going crazy...
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.
Code:
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]);
}
}
}
-
June 13th, 2009, 09:57 AM
#2
Re: another assignment going crazy...
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
-
June 13th, 2009, 10:00 AM
#3
Re: another assignment going crazy...
yes i could do that let met redo the code.. and come back here
-
June 13th, 2009, 10:11 AM
#4
Re: another assignment going crazy...
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... :/
Code:
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";
}
}
}
-
June 14th, 2009, 04:08 AM
#5
Re: another assignment going crazy...
Excude me but what is this ?
Code:
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
Code:
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?
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
June 14th, 2009, 09:33 AM
#6
Re: another assignment going crazy...
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.
-
June 14th, 2009, 10:12 AM
#7
Re: another assignment going crazy...
 Originally Posted by wigga
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?
Code:
if (number > 12345 ){
// mainstreet
}else{
// small street
}
So whats the whole assignment, what are the images for
Last edited by JonnyPoet; June 14th, 2009 at 10:21 AM.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
June 15th, 2009, 03:26 AM
#8
Re: another assignment going crazy...
because they are dices.
and its not a bad coding style to me, nothing wrong with it
-
June 15th, 2009, 04:34 AM
#9
Re: another assignment going crazy...
 Originally Posted by wigga
...and its not a bad coding style to me, nothing wrong with it
There are always different ways to handle something in life. Ignorance per sure is always the badest.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
June 15th, 2009, 08:30 AM
#10
Re: another assignment going crazy...
...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 :
Code:
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.
Code:
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
Code:
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.
Last edited by darwen; June 15th, 2009 at 08:34 AM.
-
June 17th, 2009, 06:50 AM
#11
Re: another assignment going crazy...
i ama familiar with all things pointed out.
but its just an assignment! no fuzz.
-
June 17th, 2009, 09:58 AM
#12
Re: another assignment going crazy...
 Originally Posted by wigga
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.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
June 17th, 2009, 11:00 AM
#13
Re: another assignment going crazy...
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
-
June 17th, 2009, 12:18 PM
#14
Re: another assignment going crazy...
 Originally Posted by wigga
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.
-
June 17th, 2009, 05:04 PM
#15
Re: another assignment going crazy...
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|