Skip to content
Snippets Groups Projects
Commit d1393f55 authored by Vesa Lappalainen's avatar Vesa Lappalainen :bicyclist:
Browse files

rekisteroi

parent a7f91f17
No related branches found
No related tags found
No related merge requests found
...@@ -7,5 +7,6 @@ ...@@ -7,5 +7,6 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/ohj2"/> <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/ohj2"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
...@@ -11,7 +11,7 @@ import java.io.PrintStream; ...@@ -11,7 +11,7 @@ import java.io.PrintStream;
public class Jasen { public class Jasen {
private int tunnusNro; private int tunnusNro;
private String nimi = ""; private String nimi = "";
private String hetu = ""; private String hetu = "";
private String katuosoite = ""; private String katuosoite = "";
private String postinumero = ""; private String postinumero = "";
...@@ -24,6 +24,8 @@ public class Jasen { ...@@ -24,6 +24,8 @@ public class Jasen {
private double maksu = 0; private double maksu = 0;
private String lisatietoja = ""; private String lisatietoja = "";
private static int seuraavaNro = 1;
/** /**
* Alustaa jäsenen tiedot tyhjiksi * Alustaa jäsenen tiedot tyhjiksi
...@@ -56,6 +58,38 @@ public class Jasen { ...@@ -56,6 +58,38 @@ public class Jasen {
} }
/**
* Antaa jäsenelle seuraavan rekisterinumeron.
* @return jäsenen uusi tunnusNro
* @example
* <pre name="test">
* Jasen aku1 = new Jasen();
* aku1.getTunnusNro() === 0;
* aku1.rekisteroi();
* Jasen aku2 = new Jasen();
* aku2.rekisteroi();
* int n1 = aku1.getTunnusNro();
* int n2 = aku2.getTunnusNro();
* n1 === n2-1;
* </pre>
*/
public int rekisteroi() {
this.tunnusNro = seuraavaNro;
seuraavaNro++;
return this.tunnusNro;
}
/**
* Palauttaa jäsenen tunnusnumeron.
* @return jäsenen tunnusnumero
*/
public int getTunnusNro() {
return tunnusNro;
}
/** /**
* @param args ei käytössä * @param args ei käytössä
*/ */
...@@ -63,8 +97,8 @@ public class Jasen { ...@@ -63,8 +97,8 @@ public class Jasen {
Jasen aku = new Jasen(); Jasen aku = new Jasen();
Jasen aku2 = new Jasen(); Jasen aku2 = new Jasen();
// aku.rekisteroi(); aku.rekisteroi();
// aku2.rekisteroi(); aku2.rekisteroi();
aku.tulosta(System.out); aku.tulosta(System.out);
......
package kerho.test;
// Generated by ComTest BEGIN
import static org.junit.Assert.*;
import org.junit.*;
import kerho.*;
// Generated by ComTest END
/**
* Test class made by ComTest
* @version 2022.02.21 11:09:38 // Generated by ComTest
*
*/
@SuppressWarnings({ "all" })
public class JasenTest {
// Generated by ComTest BEGIN
/** testRekisteroi66 */
@Test
public void testRekisteroi66() { // Jasen: 66
Jasen aku1 = new Jasen();
assertEquals("From: Jasen line: 68", 0, aku1.getTunnusNro());
aku1.rekisteroi();
Jasen aku2 = new Jasen();
aku2.rekisteroi();
int n1 = aku1.getTunnusNro();
int n2 = aku2.getTunnusNro();
assertEquals("From: Jasen line: 74", n2-1, n1);
} // Generated by ComTest END
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment