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

Krister Tarnamaa #47

Open
wants to merge 2 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
38 changes: 38 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>app</groupId>
<artifactId>app</artifactId>
<packaging>jar</packaging>
<version>1</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
6 changes: 6 additions & 0 deletions src/main/java/app/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package app;

public interface Calculator{
public void increment();
public double sum();
}
35 changes: 35 additions & 0 deletions src/main/java/app/Fruit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package app;

public class Fruit implements Calculator{

int amount;
double price;
String name;
public Fruit(String name, int amount, double price){

this.name = name;
this.amount = amount;
this.price = price;

}
public void increment(){

this.amount = this.amount+1;

}
public double sum(){

return this.amount*price;

}
public String getName(){

return this.name;
}
public String toString(){

return "Number of "+name+"s: "+this.amount+". Price for one: "+price+". Sum: "+sum();

}

}
50 changes: 50 additions & 0 deletions src/main/java/app/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package app;

import java.util.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class Main{


Fruit apple = new Fruit("Apple", 1, 3);
Fruit banana = new Fruit("Banana", 1, 2);

List<Fruit> fruits = new ArrayList<Fruit>(){{
add(apple);
add(banana);
}};

@RequestMapping("/increment")
public String increment(String fruit){

for(Fruit f: fruits){
if(f.getName().equals(fruit)){
f.increment();
return f.toString();
}
}
return "error";
}

@RequestMapping("/sum")
public String calculateSum(String fruit){

for(Fruit f: fruits){
if(f.getName().equals(fruit)){
return "Sum: "+f.sum();
}
}
return "Error";
}

public static void main(String[] args){
System.getProperties().put("server.port", 37878);
SpringApplication.run(Main.class, args);

}
}
6 changes: 6 additions & 0 deletions src/main/java/app/calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package app;

public interface Calculator{
public void increment();
public double sum();
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
server.port = 8080
36 changes: 36 additions & 0 deletions src/main/resources/public/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<html>
<head>
<title>Calculator</title>

<script>
var connection=new XMLHttpRequest();
connection.onreadystatechange=receivedData;
function increment(){
var fruit=document.getElementById("selection").value;
connection.open("GET", "/increment?fruit="+fruit, true);
connection.send();
}
function sum(){
var fruit=document.getElementById("selection").value;
connection.open("GET", "/sum?fruit="+fruit, true);
connection.send();
}
function receivedData(){
document.getElementById("response").innerHTML=connection.responseText;
}
</script>

</head>

<body>


<select id="selection">
<option value="Apple">Apple</option>
<option value="Banana">Banana</option>
</select>
<input type="button" value="Increment" id="increment" onclick="increment()"/>
<input type="button" value="Sum" id="sum" onclick="sum()" />
<div id="response"></div>
</body>
</html>
23 changes: 23 additions & 0 deletions src/test/java/app/FruitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package app;

import org.junit.*;
import static org.junit.Assert.*;

public class FruitTest{

@Test
public void incrementTest(){
Fruit apple = new Fruit("Apple", 1, 3);
apple.increment();
assertEquals(2, apple.amount);
}

@Test
public void sumTest(){
Fruit apple = new Fruit("Apple", 2, 5);
apple.increment();
apple.increment();
assertEquals(20, apple.sum(), 0.1);
}

}
Binary file added target/app-1.jar
Binary file not shown.
Binary file added target/app-1.jar.original
Binary file not shown.
Binary file added target/classes/app/Calculator.class
Binary file not shown.
Binary file added target/classes/app/Fruit.class
Binary file not shown.
Binary file added target/classes/app/Main$1.class
Binary file not shown.
Binary file added target/classes/app/Main.class
Binary file not shown.
1 change: 1 addition & 0 deletions target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
server.port = 8080
36 changes: 36 additions & 0 deletions target/classes/public/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<html>
<head>
<title>Calculator</title>

<script>
var connection=new XMLHttpRequest();
connection.onreadystatechange=receivedData;
function increment(){
var fruit=document.getElementById("selection").value;
connection.open("GET", "/increment?fruit="+fruit, true);
connection.send();
}
function sum(){
var fruit=document.getElementById("selection").value;
connection.open("GET", "/sum?fruit="+fruit, true);
connection.send();
}
function receivedData(){
document.getElementById("response").innerHTML=connection.responseText;
}
</script>

</head>

<body>


<select id="selection">
<option value="Apple">Apple</option>
<option value="Banana">Banana</option>
</select>
<input type="button" value="Increment" id="increment" onclick="increment()"/>
<input type="button" value="Sum" id="sum" onclick="sum()" />
<div id="response"></div>
</body>
</html>
5 changes: 5 additions & 0 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Generated by Apache Maven
#Tue May 30 13:46:03 EEST 2017
version=1
groupId=app
artifactId=app
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app/Main$1.class
app/Main.class
app/Fruit.class
app/Calculator.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/home/kristarn/public_html/Java/t09tervikveeb/src/main/java/app/Calculator.java
/home/kristarn/public_html/Java/t09tervikveeb/src/main/java/app/Fruit.java
/home/kristarn/public_html/Java/t09tervikveeb/src/main/java/app/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/FruitTest.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/kristarn/public_html/Java/t09tervikveeb/src/test/java/app/FruitTest.java
62 changes: 62 additions & 0 deletions target/surefire-reports/TEST-app.FruitTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="app.FruitTest" time="0.013" tests="2" errors="0" skipped="0" failures="0">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="sun.boot.library.path" value="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64"/>
<property name="java.vm.version" value="25.121-b13"/>
<property name="java.vm.vendor" value="Oracle Corporation"/>
<property name="maven.multiModuleProjectDirectory" value="/home/kristarn/public_html/Java/t09tervikveeb"/>
<property name="java.vendor.url" value="http://java.oracle.com/"/>
<property name="path.separator" value=":"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="file.encoding.pkg" value="sun.io"/>
<property name="user.country" value="US"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="sun.os.patch.level" value="unknown"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="/home/kristarn/public_html/Java/t09tervikveeb"/>
<property name="java.runtime.version" value="1.8.0_121-b13"/>
<property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/>
<property name="java.endorsed.dirs" value="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/endorsed"/>
<property name="os.arch" value="amd64"/>
<property name="java.io.tmpdir" value="/tmp"/>
<property name="line.separator" value="&#10;"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="os.name" value="Linux"/>
<property name="classworlds.conf" value="/opt/rh/rh-maven33/root/usr/share/maven/bin/m2.conf"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.library.path" value="/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.class.version" value="52.0"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="os.version" value="2.6.32-642.11.1.el6.x86_64"/>
<property name="user.home" value="/home/kristarn"/>
<property name="user.timezone" value="Europe/Tallinn"/>
<property name="java.awt.printerjob" value="sun.print.PSPrinterJob"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.specification.version" value="1.8"/>
<property name="user.name" value="kristarn"/>
<property name="java.class.path" value="/opt/rh/rh-maven33/root/usr/share/maven/boot/plexus-classworlds.jar"/>
<property name="java.vm.specification.version" value="1.8"/>
<property name="sun.arch.data.model" value="64"/>
<property name="java.home" value="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre"/>
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher package"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="user.language" value="en"/>
<property name="awt.toolkit" value="sun.awt.X11.XToolkit"/>
<property name="java.vm.info" value="mixed mode"/>
<property name="java.version" value="1.8.0_121"/>
<property name="java.ext.dirs" value="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/ext:/usr/java/packages/lib/ext"/>
<property name="sun.boot.class.path" value="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/resources.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/jsse.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/jce.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/charsets.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/jfr.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/classes"/>
<property name="java.vendor" value="Oracle Corporation"/>
<property name="maven.home" value="/opt/rh/rh-maven33/root/usr/share/maven"/>
<property name="file.separator" value="/"/>
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
<property name="sun.cpu.endian" value="little"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="sun.cpu.isalist" value=""/>
</properties>
<testcase name="sumTest" classname="app.FruitTest" time="0.013"/>
<testcase name="incrementTest" classname="app.FruitTest" time="0"/>
</testsuite>
4 changes: 4 additions & 0 deletions target/surefire-reports/app.FruitTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-------------------------------------------------------------------------------
Test set: app.FruitTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec - in app.FruitTest
Binary file added target/test-classes/app/FruitTest.class
Binary file not shown.