Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/viikko2/Ohtu-NhlStatistics1/target/
/viikko2/Ohtu-NhlStatistics1/target/
/viikko2/Verkkokauppa1/target/
Empty file added DjurabekovaNargiza/viikko1.txt
Empty file.
Empty file added DjurabekovaNargiza/viikko2.txt
Empty file.
Empty file added DjurabekovaNargiza/viikko3
Empty file.
Empty file added DjurabekovaNargiza/viikko4
Empty file.
Empty file added DjurabekovaNargiza/viikko5
Empty file.
Empty file added DjurabekovaNargiza/viikko6
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class Main {
public static void main(String[] args) {
Statistics stats = new Statistics();
// Statistics stats = new Statistics();
Statistics stats = new Statistics( new PlayerReader("http://nhlstats-2013-14.herokuapp.com/players.txt") );
System.out.println("Philadelphia Flyers");
for (Player player : stats.team("PHI") ) {
System.out.println( player );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import java.util.Scanner;

public class PlayerReader {
public class PlayerReader implements Reader{

private Scanner scanner;

Expand All @@ -18,6 +18,7 @@ public PlayerReader(String pageUrl) {
}
}


public List<Player> getPlayers() {
ArrayList<Player> players = new ArrayList<Player>();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ohtuesimerkki;

import java.util.List;

public interface Reader {

List<Player> getPlayers();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
public class Statistics {

private List<Player> players;
private Reader reader;

public Statistics() {
PlayerReader reader = new PlayerReader("http://nhlstats-2013-14.herokuapp.com/players.txt");
public Statistics(Reader reader) {
this.reader = reader;
// reader = new PlayerReader("http://nhlstats-2013-14.herokuapp.com/players.txt");
players = reader.getPlayers();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ohtuesimerkki;

import java.util.ArrayList;
import java.util.List;

/**
*
* @author nargiza
*/
class StaticsticsTest {

Statistics stats;
Reader readerStub;

// ...

public StaticsticsTest() {
this.readerStub = new Reader() {

@Override
public List<Player> getPlayers() {
ArrayList<Player> players = new ArrayList<Player>();

players.add(new Player("Semenko", "EDM", 4, 12));
players.add(new Player("Lemieux", "PIT", 45, 54));
players.add(new Player("Kurri", "EDM", 37, 53));
players.add(new Player("Yzerman", "DET", 42, 56));
players.add(new Player("Gretzky", "EDM", 35, 89));

return players;

}
};
}
}
24 changes: 20 additions & 4 deletions viikko2/Verkkokauppa1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</dependency>


<!-- SPRING -->

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
Expand All @@ -42,23 +48,33 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework.version}</version>
</dependency>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<configLocation>my_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</build>
</project>
15 changes: 13 additions & 2 deletions viikko2/Verkkokauppa1/src/main/java/ohtu/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@

import ohtu.verkkokauppa.Kauppa;
import ohtu.verkkokauppa.Kirjanpito;
//import ohtu.verkkokauppa.Pankki;
//import ohtu.verkkokauppa.Varasto;
//import ohtu.verkkokauppa.Viitegeneraattori;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class Main {

public static void main(String[] args) {
Kauppa kauppa = new Kauppa();
ApplicationContext ctx = new FileSystemXmlApplicationContext("src/main/resources/spring-context.xml");
Kauppa kauppa = ctx.getBean(Kauppa.class);
Kirjanpito kirjanpito = new Kirjanpito();
//Varasto varasto = new Varasto(kirjanpito);
//Pankki pankki = new Pankki(kirjanpito);
//Viitegeneraattori viitegen = new Viitegeneraattori();
//Kauppa kauppa = new Kauppa(varasto, pankki, viitegen);

// kauppa hoitaa yhden asiakkaan kerrallaan seuraavaan tapaan:
kauppa.aloitaAsiointi();
Expand All @@ -25,7 +36,7 @@ public static void main(String[] args) {
kauppa.tilimaksu("Arto Vihavainen", "3425-1652");

// kirjanpito
for (String tapahtuma : Kirjanpito.getInstance().getTapahtumat()) {
for (String tapahtuma : kirjanpito.getTapahtumat()) {
System.out.println(tapahtuma);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ public class Kauppa {
private Viitegeneraattori viitegeneraattori;
private String kaupanTili;

public Kauppa() {
varasto = Varasto.getInstance();
pankki = Pankki.getInstance();
viitegeneraattori = Viitegeneraattori.getInstance();

public Kauppa(Varasto varasto, Pankki pankki, Viitegeneraattori viitegeneraattori){
this.varasto = varasto;
this.pankki = pankki;
this.viitegeneraattori = viitegeneraattori;
kaupanTili = "33333-44455";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@
import java.util.ArrayList;

public class Kirjanpito {
private static Kirjanpito instance;

public static Kirjanpito getInstance() {
if ( instance==null) {
instance = new Kirjanpito();
}

return instance;
}

private ArrayList<String> tapahtumat;
public ArrayList<String> tapahtumat;

private Kirjanpito() {
public Kirjanpito() {
tapahtumat = new ArrayList<String>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

import java.util.ArrayList;

public class Ostoskori {
public class Ostoskori implements Ostoskori_inteface {

ArrayList<Tuote> tuotteet;

public Ostoskori() {
tuotteet = new ArrayList<Tuote>();
}

@Override
public void lisaa(Tuote t) {
tuotteet.add(t);
}

@Override
public void poista(Tuote t) {
tuotteet.remove(t);
}

@Override
public int hinta() {
int hinta = 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ohtu.verkkokauppa;

/**
*
* @author nargiza
*/
public interface Ostoskori_inteface {

int hinta();

void lisaa(Tuote t);

void poista(Tuote t);

}
17 changes: 6 additions & 11 deletions viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Pankki.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package ohtu.verkkokauppa;

public class Pankki {
public class Pankki implements Pankki_interface {

private static Pankki instanssi;

public static Pankki getInstance() {
if (instanssi == null) {
instanssi = new Pankki();
}
public Kirjanpito kirjanpito;

return instanssi;
public Pankki(Kirjanpito kirjanpito) {
this.kirjanpito = kirjanpito;
}
private Kirjanpito kirjanpito;

private Pankki() {
kirjanpito = Kirjanpito.getInstance();
}


@Override
public boolean tilisiirto(String nimi, int viitenumero, String tililta, String tilille, int summa) {
kirjanpito.lisaaTapahtuma("tilisiirto: tililtä " + tilille + " tilille " + tilille
+ " viite " + viitenumero + " summa " + summa + "e");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ohtu.verkkokauppa;

/**
*
* @author nargiza
*/
public interface Pankki_interface {

boolean tilisiirto(String nimi, int viitenumero, String tililta, String tilille, int summa);

}
26 changes: 12 additions & 14 deletions viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Varasto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@

import java.util.*;

public class Varasto {

private static Varasto instanssi;
public class Varasto implements Varasto_interface {

public static Varasto getInstance() {
if (instanssi == null) {
instanssi = new Varasto();
}

return instanssi;
}
public Kirjanpito kirjanpito;
public HashMap<Tuote, Integer> saldot;

private Kirjanpito kirjanpito;
private HashMap<Tuote, Integer> saldot;

private Varasto() {
kirjanpito = Kirjanpito.getInstance();
public Varasto(Kirjanpito kirjanpito) {
this.kirjanpito = kirjanpito;
saldot = new HashMap<Tuote, Integer>();
alustaTuotteet();
}

@Override
public Tuote haeTuote(int id){
for (Tuote t : saldot.keySet()) {
if ( t.getId()==id) return t;
Expand All @@ -31,15 +23,20 @@ public Tuote haeTuote(int id){
return null;
}


@Override
public int saldo(int id){
return saldot.get(haeTuote(id));
}


@Override
public void otaVarastosta(Tuote t){
saldot.put(t, saldo(t.getId())-1 );
kirjanpito.lisaaTapahtuma("otettiin varastosta "+t);
}

@Override
public void palautaVarastoon(Tuote t){
saldot.put(t, saldo(t.getId())+1 );
kirjanpito.lisaaTapahtuma("palautettiin varastoon "+t);
Expand All @@ -52,4 +49,5 @@ private void alustaTuotteet() {
saldot.put(new Tuote(4, "Mikkeller not just another Wit", 7), 40);
saldot.put(new Tuote(5, "Weihenstephaner Hefeweisse", 4), 15);
}

}
Loading