473,499 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't get the counter to work!!!

1 New Member
Hi,
I'm pretty new to programming and new to this site too for that matter...I doing my first programming course at my university andnow I've been stuck with this problem all day. If somebody could take a look at the code below, it seems to work fine otherwise but the counter (count) don't seem to want to increase.

Expand|Select|Wrap|Line Numbers
  1. public class Alkuelain {
  2.   //Testipääohjelma käyttää alla olevia vakioita - ÄLÄ POISTA
  3.   int geenit[];
  4.   int individ;
  5.   int count=1;
  6.  
  7.   public static final int GEENIEN_MAARA = 10;
  8.   public static final int PIENIN_GEENI = 0;
  9.   public static final int SUURIN_GEENI = 3;
  10.  
  11.  
  12.    public Alkuelain(){
  13.      this.geenit = new int[]{0,0,0,0,0,0,0,0,0,0};
  14.      this.individ = count;
  15.      count++;
  16.    }
  17.  
  18.    public Alkuelain(int[] perima){
  19.      if (perima.length != 10)
  20.       return;
  21.      for (int i = 0; i <perima.length; i ++){
  22.        if (perima[i]<0 || perima[i]>3)
  23.          return;
  24.      }
  25.  
  26.      this.geenit = perima;
  27.      this.individ = count;
  28.      count++;
  29.    }
  30.  
  31.    public void mutaatio(int geeniNro, int uusiGeeni){
  32.      if (geeniNro<0 || geeniNro>9)
  33.        return;
  34.      if (uusiGeeni<0 || uusiGeeni>3)
  35.        return;
  36.      this.geenit[geeniNro] = uusiGeeni;
  37.    }
  38.  
  39.    public Alkuelain klooni(){
  40.      Alkuelain klooni = new Alkuelain(this.geenit);
  41.      return klooni;
  42.    }
  43.  
  44.    public Alkuelain pariudu(Alkuelain toinen){
  45.      Alkuelain son = new Alkuelain();
  46.      for (int i = 0; i < GEENIEN_MAARA; i ++){
  47.        int a = (this.geenit[i] + toinen.geenit[i])/2;
  48.        son.geenit[i]=a;
  49.      }
  50.      return son;
  51.    }
  52.  
  53.    public String toString(){
  54.      String perima = "";
  55.      for (int i =0; i < GEENIEN_MAARA - 1; i++)
  56.        perima += this.geenit[i] + ", ";
  57.      perima += this.geenit[GEENIEN_MAARA - 1] + " }";
  58.      return "Alkueläin, numero: " + this.individ + ", perimä: { " + perima;
  59.    }
  60.  
  61. }
  62.  
Im sure this will take no time at all for somebody more gifted than me...I really appreciate any help.

Thanks
Mar 16 '07 #1
2 1227
sicarie
4,677 Recognized Expert Moderator Specialist
Hi,
I'm pretty new to programming and new to this site too for that matter...I doing my first programming course at my university andnow I've been stuck with this problem all day. If somebody could take a look at the code below, it seems to work fine otherwise but the counter (count) don't seem to want to increase.

Expand|Select|Wrap|Line Numbers
  1. public class Alkuelain {
  2.   //Testipääohjelma käyttää alla olevia vakioita - ÄLÄ POISTA
  3.   int geenit[];
  4.   int individ;
  5.   int count=1;
  6.  
  7.   public static final int GEENIEN_MAARA = 10;
  8.   public static final int PIENIN_GEENI = 0;
  9.   public static final int SUURIN_GEENI = 3;
  10.  
  11.  
  12.    public Alkuelain(){
  13.      this.geenit = new int[]{0,0,0,0,0,0,0,0,0,0};
  14.      this.individ = count;
  15.      count++;
  16.    }
  17.  
  18.    public Alkuelain(int[] perima){
  19.      if (perima.length != 10)
  20.       return;
  21.      for (int i = 0; i <perima.length; i ++){
  22.        if (perima[i]<0 || perima[i]>3)
  23.          return;
  24.      }
  25.  
  26.      this.geenit = perima;
  27.      this.individ = count;
  28.      count++;
  29.    }
  30.  
  31.    public void mutaatio(int geeniNro, int uusiGeeni){
  32.      if (geeniNro<0 || geeniNro>9)
  33.        return;
  34.      if (uusiGeeni<0 || uusiGeeni>3)
  35.        return;
  36.      this.geenit[geeniNro] = uusiGeeni;
  37.    }
  38.  
  39.    public Alkuelain klooni(){
  40.      Alkuelain klooni = new Alkuelain(this.geenit);
  41.      return klooni;
  42.    }
  43.  
  44.    public Alkuelain pariudu(Alkuelain toinen){
  45.      Alkuelain son = new Alkuelain();
  46.      for (int i = 0; i < GEENIEN_MAARA; i ++){
  47.        int a = (this.geenit[i] + toinen.geenit[i])/2;
  48.        son.geenit[i]=a;
  49.      }
  50.      return son;
  51.    }
  52.  
  53.    public String toString(){
  54.      String perima = "";
  55.      for (int i =0; i < GEENIEN_MAARA - 1; i++)
  56.        perima += this.geenit[i] + ", ";
  57.      perima += this.geenit[GEENIEN_MAARA - 1] + " }";
  58.      return "Alkueläin, numero: " + this.individ + ", perimä: { " + perima;
  59.    }
  60.  
  61. }
  62.  
Im sure this will take no time at all for somebody more gifted than me...I really appreciate any help.

Thanks
What is this class doing? It seems to me that the base is set at 1, and then each separate instantiation increments that 1. You either want a singleton class - which will create only one instance of Alkuelain, or have a setCounter() method that will increment the counter.
Mar 16 '07 #2
r035198x
13,262 MVP
Hi,
I'm pretty new to programming and new to this site too for that matter...I doing my first programming course at my university andnow I've been stuck with this problem all day. If somebody could take a look at the code below, it seems to work fine otherwise but the counter (count) don't seem to want to increase.

Expand|Select|Wrap|Line Numbers
  1. public class Alkuelain {
  2. //Testipääohjelma käyttää alla olevia vakioita - ÄLÄ POISTA
  3. int geenit[];
  4. int individ;
  5. int count=1;
  6.  
  7. public static final int GEENIEN_MAARA = 10;
  8. public static final int PIENIN_GEENI = 0;
  9. public static final int SUURIN_GEENI = 3;
  10.  
  11.  
  12. public Alkuelain(){
  13. this.geenit = new int[]{0,0,0,0,0,0,0,0,0,0};
  14. this.individ = count;
  15. count++;
  16. }
  17.  
  18. public Alkuelain(int[] perima){
  19. if (perima.length != 10)
  20. return;
  21. for (int i = 0; i <perima.length; i ++){
  22. if (perima[i]<0 || perima[i]>3)
  23. return;
  24. }
  25.  
  26. this.geenit = perima;
  27. this.individ = count;
  28. count++;
  29. }
  30.  
  31. public void mutaatio(int geeniNro, int uusiGeeni){
  32. if (geeniNro<0 || geeniNro>9)
  33. return;
  34. if (uusiGeeni<0 || uusiGeeni>3)
  35. return;
  36. this.geenit[geeniNro] = uusiGeeni;
  37. }
  38.  
  39. public Alkuelain klooni(){
  40. Alkuelain klooni = new Alkuelain(this.geenit);
  41. return klooni;
  42. }
  43.  
  44. public Alkuelain pariudu(Alkuelain toinen){
  45. Alkuelain son = new Alkuelain();
  46. for (int i = 0; i < GEENIEN_MAARA; i ++){
  47. int a = (this.geenit[i] + toinen.geenit[i])/2;
  48. son.geenit[i]=a;
  49. }
  50. return son;
  51. }
  52.  
  53. public String toString(){
  54. String perima = "";
  55. for (int i =0; i < GEENIEN_MAARA - 1; i++)
  56. perima += this.geenit[i] + ", ";
  57. perima += this.geenit[GEENIEN_MAARA - 1] + " }";
  58. return "Alkueläin, numero: " + this.individ + ", perimä: { " + perima;
  59. }
  60.  
  61. }
  62.  
Im sure this will take no time at all for somebody more gifted than me...I really appreciate any help.

Thanks
How are you running it? What do you want the program to do? If you post the class with the main method and explain what you want the program to do perhaps it would be easier to help.
Mar 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1868
by: Nikolai Onken | last post by:
Hey, I got a rather more mathematical Problem but have no idea how to solve it: I have following values and want them to return other values as stated below: (Best seen with fixed pitch font)...
1
2381
by: chuck amadi | last post by:
By the way list is there a better way than using the readlines() to > > >parse the mail data into a file , because Im using > > >email.message_from_file it returns > > >all the data i.e reads one...
2
1775
by: Yogi_Bear_79 | last post by:
I have a for each loop, that currently runs through an array of 11,000+ items. I exerpted the code part below that I have a question on. I thought this code would update the form label and...
3
21054
by: kaiser | last post by:
Hello, Am new to C# and am playing around trying to get a while loop to display a int on a windows console using label. private void btnGo_Click(object sender, System.EventArgs e) { int Counter...
6
4837
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
12
3848
by: vietgurlqt | last post by:
I don't what is wrong my site but some of my members cant view it on firefox. I been browsing the net for answer but i havent find the solution. Some said add <!DOCTYPE HTML PUBLIC "-//W3C//DTD...
19
2238
by: bb nicole | last post by:
Below is my search engine for job portal which jobseeker can find the job through quick search. But it cant work... Is it mysql query got problem?? Thanx.. Interface <html> <head> <title>UMS...
1
1607
by: jjr0319 | last post by:
i'm very new to C#. i have homework for a class im taking that i just cant figure out. we're working with events & delegates. the particular event is a clock, and when a minute elapses, i have to run...
4
1514
by: rez151 | last post by:
trying to create a tree of hash nodes, with each node having a max of 5 objects, and a maximum of 5 child nodes...we insert 6 sucesfully and "explode" to create 3 child nodes, but when it gets to 7...
1
4361
by: TrippW06 | last post by:
I working on a program to analyze a string and tell the user how may of each char is in the sentence. I have it sorta working but cant fidgure it out. I get a weird last line and my method to remove...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.