Skip to content
Snippets Groups Projects
Commit e110efbc authored by Jesse Laine's avatar Jesse Laine
Browse files

Rekisteröintiä lisätty.

parent d6a029e5
No related branches found
No related tags found
No related merge requests found
package taidegalleria;
import java.io.OutputStream;
import java.io.PrintStream;
/**
......@@ -35,6 +36,8 @@ public class Taiteilija {
private String kansalaisuus = "";
private String tyylisuunta = "";
public static int seuraavaId = 1;
/**
* Muodostaa tyhjnä taiteilijan.
......@@ -55,13 +58,47 @@ public class Taiteilija {
}
/** Ei tarvita vielä: */
// public void tulosta(OutputStream os) { tulosta(new PrintStream(os)); }
/**
* Antaa taiteilijalle seuraavan id:n.
* @return taiteilijan uusi tunnusId
* @example
* <pre name="test">
* Taiteilija a1 = new Taiteilija();
* a1.getId() === 0;
* a1.rekisteroi();
* Taiteilija a2 = new Taiteilija();
* a2.rekisteroi();
* int n1 = a1.getId();
* int n2 = a2.getId();
* n1 === n2-1;
* </pre>
*/
public int rekisteroi() {
this.id = seuraavaId;
seuraavaId++;
return this.id;
}
/**
* Palauttaa taiteilijan id:n.
* @return taiteilijan id
*/
public int getId() {
return id;
}
public static void main(String[] args) {
Taiteilija hiroshige = new Taiteilija();
Taiteilija edward = new Taiteilija();
// hiroshige.rekisteroi();
// edward.rekisteroi();
hiroshige.rekisteroi();
edward.rekisteroi();
hiroshige.tulosta(System.out);
edward.tulosta(System.out);
......
package taidegalleria.test;
// Generated by ComTest BEGIN
import static org.junit.Assert.*;
import org.junit.*;
import taidegalleria.*;
// Generated by ComTest END
/**
* Test class made by ComTest
* @version 2025.02.24 16:09:25 // Generated by ComTest
*
*/
@SuppressWarnings({ "PMD" })
public class TaiteilijaTest {
// Generated by ComTest BEGIN
/** testRekisteroi69 */
@Test
public void testRekisteroi69() { // Taiteilija: 69
Taiteilija a1 = new Taiteilija();
assertEquals("From: Taiteilija line: 71", 0, a1.getId());
a1.rekisteroi();
Taiteilija a2 = new Taiteilija();
a2.rekisteroi();
int n1 = a1.getId();
int n2 = a2.getId();
assertEquals("From: Taiteilija line: 77", 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