diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5ff6309b7199129c1afe4f4ec1906e640bec48c6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..26d33521af10bcc7fd8cea344038eaaeb78d0ef5 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000000000000000000000000000000000000..aa00ffab7828f4818589659c804ec2cfd99baed3 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Encoding"> + <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> + <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..970f0958ef542b343f23372574700712e76c520a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ExternalStorageConfigurationManager" enabled="true" /> + <component name="MavenProjectsManager"> + <option name="originalFiles"> + <list> + <option value="$PROJECT_DIR$/pom.xml" /> + </list> + </option> + <option name="workspaceImportForciblyTurnedOn" value="true" /> + </component> + <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..0f1acf836f6e2d9d9c7a0e7348184ed141335f7b --- /dev/null +++ b/pom.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>fi.utu.omatunnus</groupId> + <artifactId>Viikko4-1</artifactId> + <version>1.0-SNAPSHOT</version> + + <properties> + <maven.compiler.source>21</maven.compiler.source> + <maven.compiler.target>21</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>5.9.2</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.22.2</version> + </plugin> + </plugins> + </build> + +</project> \ No newline at end of file diff --git a/src/main/java/Kirjahylly.java b/src/main/java/Kirjahylly.java new file mode 100644 index 0000000000000000000000000000000000000000..ffc5dfe626c4fa870b7394a2e554577578e35c0e --- /dev/null +++ b/src/main/java/Kirjahylly.java @@ -0,0 +1,57 @@ +import java.util.ArrayList; + +/** + * Luokka mallintaa yksinkertaista kirjahyllyä + */ +public class Kirjahylly { + private ArrayList<String> kirjat; + + private int kirjojaHyllyssa = 0; + + public Kirjahylly() { + kirjat = new ArrayList<>(); + kirjojaHyllyssa = 0; + } + + /** + * Lisää yhden kirjan hyllyyn + * @param kirja lisättävä kirja + */ + public void lisaaKirja(String kirja) { + kirjat.add(kirja); + kirjojaHyllyssa = kirjojaHyllyssa + 1; + + } + + /** + * Palauttaa kirjahyllyyn viimeksi lisätyn kirjan + * @return viimeksi lisätyn kirjan + */ + public String viimeksiLisatty() { + return kirjat.get(kirjat.size() - 1); + } + + /** + * Palauttaa tiedon siitä onko annettu kirja hyllyssä + * @param kirja kirja, jota etsitään + * @return <code>true</code>, jos kirjan on hyllyssä, muuten <code>false</code> + */ + public boolean onkoKirjaHyllyssa(String kirja) { + for (String k : kirjat) { + if (k == kirja) { + return true; + } + } + return false; + } + + /** + * Palautta kirjahyllyssä olevien kirjojen määrän + * @return kirjojen määrän hyllyssä + */ + public int getKirjojaHyllyssa() { + + return kirjojaHyllyssa; + } +} + diff --git a/src/main/java/fi/utu/omatunnus/Main.java b/src/main/java/fi/utu/omatunnus/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..7d69eb78968270fb4aa53d1244b00ba940add253 --- /dev/null +++ b/src/main/java/fi/utu/omatunnus/Main.java @@ -0,0 +1,17 @@ +package fi.utu.omatunnus; + +//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or +// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter. +public class Main { + public static void main(String[] args) { + //TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + System.out.printf("Hello and welcome!"); + + for (int i = 1; i <= 5; i++) { + //TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint + // for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>. + System.out.println("i = " + i); + } + } +} \ No newline at end of file