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. -
public class Alkuelain {
-
//Testipääohjelma käyttää alla olevia vakioita - ÄLÄ POISTA
-
int geenit[];
-
int individ;
-
int count=1;
-
-
public static final int GEENIEN_MAARA = 10;
-
public static final int PIENIN_GEENI = 0;
-
public static final int SUURIN_GEENI = 3;
-
-
-
public Alkuelain(){
-
this.geenit = new int[]{0,0,0,0,0,0,0,0,0,0};
-
this.individ = count;
-
count++;
-
}
-
-
public Alkuelain(int[] perima){
-
if (perima.length != 10)
-
return;
-
for (int i = 0; i <perima.length; i ++){
-
if (perima[i]<0 || perima[i]>3)
-
return;
-
}
-
-
this.geenit = perima;
-
this.individ = count;
-
count++;
-
}
-
-
public void mutaatio(int geeniNro, int uusiGeeni){
-
if (geeniNro<0 || geeniNro>9)
-
return;
-
if (uusiGeeni<0 || uusiGeeni>3)
-
return;
-
this.geenit[geeniNro] = uusiGeeni;
-
}
-
-
public Alkuelain klooni(){
-
Alkuelain klooni = new Alkuelain(this.geenit);
-
return klooni;
-
}
-
-
public Alkuelain pariudu(Alkuelain toinen){
-
Alkuelain son = new Alkuelain();
-
for (int i = 0; i < GEENIEN_MAARA; i ++){
-
int a = (this.geenit[i] + toinen.geenit[i])/2;
-
son.geenit[i]=a;
-
}
-
return son;
-
}
-
-
public String toString(){
-
String perima = "";
-
for (int i =0; i < GEENIEN_MAARA - 1; i++)
-
perima += this.geenit[i] + ", ";
-
perima += this.geenit[GEENIEN_MAARA - 1] + " }";
-
return "Alkueläin, numero: " + this.individ + ", perimä: { " + perima;
-
}
-
-
}
-
Im sure this will take no time at all for somebody more gifted than me...I really appreciate any help.
Thanks
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. -
public class Alkuelain {
-
//Testipääohjelma käyttää alla olevia vakioita - ÄLÄ POISTA
-
int geenit[];
-
int individ;
-
int count=1;
-
-
public static final int GEENIEN_MAARA = 10;
-
public static final int PIENIN_GEENI = 0;
-
public static final int SUURIN_GEENI = 3;
-
-
-
public Alkuelain(){
-
this.geenit = new int[]{0,0,0,0,0,0,0,0,0,0};
-
this.individ = count;
-
count++;
-
}
-
-
public Alkuelain(int[] perima){
-
if (perima.length != 10)
-
return;
-
for (int i = 0; i <perima.length; i ++){
-
if (perima[i]<0 || perima[i]>3)
-
return;
-
}
-
-
this.geenit = perima;
-
this.individ = count;
-
count++;
-
}
-
-
public void mutaatio(int geeniNro, int uusiGeeni){
-
if (geeniNro<0 || geeniNro>9)
-
return;
-
if (uusiGeeni<0 || uusiGeeni>3)
-
return;
-
this.geenit[geeniNro] = uusiGeeni;
-
}
-
-
public Alkuelain klooni(){
-
Alkuelain klooni = new Alkuelain(this.geenit);
-
return klooni;
-
}
-
-
public Alkuelain pariudu(Alkuelain toinen){
-
Alkuelain son = new Alkuelain();
-
for (int i = 0; i < GEENIEN_MAARA; i ++){
-
int a = (this.geenit[i] + toinen.geenit[i])/2;
-
son.geenit[i]=a;
-
}
-
return son;
-
}
-
-
public String toString(){
-
String perima = "";
-
for (int i =0; i < GEENIEN_MAARA - 1; i++)
-
perima += this.geenit[i] + ", ";
-
perima += this.geenit[GEENIEN_MAARA - 1] + " }";
-
return "Alkueläin, numero: " + this.individ + ", perimä: { " + perima;
-
}
-
-
}
-
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.
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. -
public class Alkuelain {
-
//Testipääohjelma käyttää alla olevia vakioita - ÄLÄ POISTA
-
int geenit[];
-
int individ;
-
int count=1;
-
-
public static final int GEENIEN_MAARA = 10;
-
public static final int PIENIN_GEENI = 0;
-
public static final int SUURIN_GEENI = 3;
-
-
-
public Alkuelain(){
-
this.geenit = new int[]{0,0,0,0,0,0,0,0,0,0};
-
this.individ = count;
-
count++;
-
}
-
-
public Alkuelain(int[] perima){
-
if (perima.length != 10)
-
return;
-
for (int i = 0; i <perima.length; i ++){
-
if (perima[i]<0 || perima[i]>3)
-
return;
-
}
-
-
this.geenit = perima;
-
this.individ = count;
-
count++;
-
}
-
-
public void mutaatio(int geeniNro, int uusiGeeni){
-
if (geeniNro<0 || geeniNro>9)
-
return;
-
if (uusiGeeni<0 || uusiGeeni>3)
-
return;
-
this.geenit[geeniNro] = uusiGeeni;
-
}
-
-
public Alkuelain klooni(){
-
Alkuelain klooni = new Alkuelain(this.geenit);
-
return klooni;
-
}
-
-
public Alkuelain pariudu(Alkuelain toinen){
-
Alkuelain son = new Alkuelain();
-
for (int i = 0; i < GEENIEN_MAARA; i ++){
-
int a = (this.geenit[i] + toinen.geenit[i])/2;
-
son.geenit[i]=a;
-
}
-
return son;
-
}
-
-
public String toString(){
-
String perima = "";
-
for (int i =0; i < GEENIEN_MAARA - 1; i++)
-
perima += this.geenit[i] + ", ";
-
perima += this.geenit[GEENIEN_MAARA - 1] + " }";
-
return "Alkueläin, numero: " + this.individ + ", perimä: { " + perima;
-
}
-
-
}
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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)...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |