Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viikko 6 #376

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/viikko2/Ohtu-NhlStatistics1/target/
/viikko2/Ohtu-NhlStatistics1/target/
/viikko2/RiippuvuuksienInjektointi1/target/
/viikko2/RiippuvuuksienInjektointi2/target/
/viikko2/Verkkokauppa1/target/
Empty file added JoentaustaJohanna/viikko1
Empty file.
Empty file added JoentaustaJohanna/viikko2
Empty file.
Empty file added JoentaustaJohanna/viikko3
Empty file.
Empty file added JoentaustaJohanna/viikko4
Empty file.
Empty file added JoentaustaJohanna/viikko5
Empty file.
Empty file added JoentaustaJohanna/viikko6
Empty file.
1 change: 1 addition & 0 deletions branchhaara1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asfafs
1 change: 1 addition & 0 deletions haara1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asgf
1 change: 1 addition & 0 deletions haara2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asfafsasf
5 changes: 5 additions & 0 deletions muutos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<<<<<<< HEAD
asfasf
=======
asfafs
>>>>>>> f770baca63659e6ee24000456486e058ba68d736
1 change: 1 addition & 0 deletions tiedostoo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asfafs
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( 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 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 ohtuesimerkki;

import java.util.List;

/**
*
* @author Jussi
*/
public interface Reader {
List<Player> getPlayers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public class Statistics {

private List<Player> players;

public Statistics() {
PlayerReader reader = new PlayerReader("http://nhlstats-2013-14.herokuapp.com/players.txt");
public Statistics(Reader iReader) {
Reader reader = iReader;
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,83 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ohtuesimerkki;

import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Jussi
*/
public class StatisticsTest {

Statistics stats;
Reader 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;
}
};

public StatisticsTest() {
}

@BeforeClass
public static void setUpClass() throws Exception {
}

@AfterClass
public static void tearDownClass() throws Exception {
}

@Before
public void setUp() {
stats = new Statistics(readerStub);
}

@After
public void tearDown() {
}

@Test
public void searchTest() {
assertEquals("Kurri", stats.search("Kurri").getName());
}

@Test
public void topTest() {
assertEquals("Gretzky", stats.topScorers(1).get(0).getName());
}

@Test
public void teamTest() {
assertEquals("Lemieux", stats.team("PIT").get(0).getName());

}

@Test
public void nullsearchTest() {
assertEquals(null, stats.search("Jussi"));
}
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
// @Test
// public void hello() {}
}
31 changes: 15 additions & 16 deletions viikko2/RiippuvuuksienInjektointi1/src/main/java/ohtu/Laskin.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
package ohtu;

import java.util.Scanner;
import ohtu.laskin.IO;

public class Laskin {
private IO io;

private Scanner lukija;

public Laskin() {
lukija = new Scanner(System.in);
public Laskin(IO io) {
this.io = io;
}

public void suorita(){
while( true ) {
System.out.print("luku 1: ");
int luku1 = lukija.nextInt();
io.print("luku 1: ");
int luku1 = io.nextInt();
if ( luku1==-9999 ) return;
System.out.print("luku 2: ");
int luku2 = lukija.nextInt();
if ( luku2==-9999 ) return;

io.print("luku 2: ");
int luku2 = io.nextInt();
if ( luku2==-9999 ) return;

int vastaus = laskeSumma(luku1, luku2);
System.out.println("summa: "+ vastaus);
io.print("summa: "+vastaus+"\n");
}
}

private int laskeSumma(int luku1, int luku2) {
return luku1+luku2;
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public class Main {
public static void main(String[] args) {
new ohtu.laskin.Laskin(new KonsoliIO()).suorita();
Laskin laskin = new Laskin( new KonsoliIO() );
laskin.suorita();
// new ohtu.laskin.Laskin(new KonsoliIO()).suorita();
}
}
24 changes: 20 additions & 4 deletions viikko2/Verkkokauppa1/src/main/java/ohtu/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@

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();

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

// kauppa hoitaa yhden asiakkaan kerrallaan seuraavaan tapaan:
kauppa.aloitaAsiointi();
kauppa.lisaaKoriin(1);
Expand All @@ -25,7 +41,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
34 changes: 21 additions & 13 deletions viikko2/Verkkokauppa1/src/main/java/ohtu/verkkokauppa/Kauppa.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
package ohtu.verkkokauppa;

public class Kauppa {
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

private Varasto varasto;
private Pankki pankki;
private Ostoskori ostoskori;
private Viitegeneraattori viitegeneraattori;
@Component
public class Kauppa{

private VarastoInterface varasto;
private PankkiInterface pankki;
private OstoskoriInterface ostoskori;
private ViitegeneraattoriInterface viitegeneraattori;
private String kaupanTili;

public Kauppa() {
varasto = Varasto.getInstance();
pankki = Pankki.getInstance();
viitegeneraattori = Viitegeneraattori.getInstance();
kaupanTili = "33333-44455";
@Autowired
public Kauppa(VarastoInterface varasto, PankkiInterface pankki, ViitegeneraattoriInterface viitegeneraattori) {
this.varasto=varasto;
this.pankki=pankki;
this.viitegeneraattori=viitegeneraattori;
this.kaupanTili="33333-44455";
}


public void aloitaAsiointi() {
ostoskori = new Ostoskori();
}


public void poistaKorista(int id) {
Tuote t = varasto.haeTuote(id);
Tuote t = varasto.haeTuote(id);
varasto.palautaVarastoon(t);
}


public void lisaaKoriin(int id) {
if (varasto.saldo(id)>0) {
Tuote t = varasto.haeTuote(id);
Tuote t = varasto.haeTuote(id);
ostoskori.lisaa(t);
varasto.otaVarastosta(t);
}
Expand All @@ -39,4 +47,4 @@ public boolean tilimaksu(String nimi, String tiliNumero) {
return pankki.tilisiirto(nimi, viite, tiliNumero, kaupanTili, summa);
}

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

/**
*
* @author Jussi
*/
public interface KauppaInterface {

void aloitaAsiointi();

void lisaaKoriin(int id);

void poistaKorista(int id);

boolean tilimaksu(String nimi, String tiliNumero);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@

import java.util.ArrayList;

public class Kirjanpito {
private static Kirjanpito instance;

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

return instance;
}
public class Kirjanpito implements KirjanpitoInterface {
// private static Kirjanpito instance;
//
// public static Kirjanpito getInstance() {
// if ( instance==null) {
// instance = new Kirjanpito();
// }
//
// return instance;
// }

private ArrayList<String> tapahtumat;

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

@Override
public void lisaaTapahtuma(String tapahtuma) {
tapahtumat.add(tapahtuma);
}

@Override
public ArrayList<String> getTapahtumat() {
return tapahtumat;
}
Expand Down
Loading