Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .idea/dbnavigator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions functional-requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Project 1: Väder-baserad Klädväljare

FR1: Returnera "Vinterjacka" om temperaturen understiger 0 grader;
FR2: Returnera "Tshirt" om temperaturen överstiger 15 grader;
FR3: Lägg till "ta med Paraply" om nederbörd;
FR4: Hantera undantag.

Project 2: Prishantering

FR1:
16 changes: 16 additions & 0 deletions opencode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://opencode.ai/config.json",
"permission": {
"edit": {
"pom.xml": "deny"
}

},
"mcp":{
"context7": {
"type": "remote",
"url" : "https://mcp.context7.com/mcp",
"enabled": true
}
}
}
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@
<version>3.27.6</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
53 changes: 53 additions & 0 deletions src/main/java/org/example/Bowling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.example;

public class Bowling {
private int[] rolls = new int[20];
private int rollCount = 0;



public void roll(int pins){
if (pins == 10)
rollCount++;
rolls[rollCount++] = pins;
}

private boolean isFinalFrame(){
return rollCount > 18;
}
public int score(){
int score = 0;
for (int i = 0; i < rolls.length; i+=2) {
if(isStrike(i))
score += strikeBonus(i);
else if(isSpare(i)){
score += rolls[i] + rolls[i + 1] + spareBonus(i);
} else
score += rolls[i] + rolls[i + 1];

}
return score;
}

private int spareBonus(int i){
return rolls[i + 2];
}

private int strikeBonus(int i){
if (i == 16)
return rolls[i+1] + rolls[i+2];
if(rolls[i + 2] == 10)
return rolls[i + 2] + rolls[i + 4];
return rolls[i + 2] + rolls[i + 3];
}

public boolean isStrike(int i){
return rolls[i] == 10;

}

public boolean isSpare(int i){

return rolls[i] == 0 && rolls[i + 1] == 10;
}
}
30 changes: 30 additions & 0 deletions src/main/java/org/example/CSV/CsvTodoStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.example.CSV;

import org.example.todolist.TodoItem;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

public class CsvTodoStorage {


public void write(List<TodoItem> items, Writer out) throws IOException {
out.write("id,task,due\n");

for (TodoItem item : items) {
out.write(item.getId() + ",\"Buy milk, \"\"organic\"\"\"");
out.write(escapeCsv(item.getTask()) + ",");
out.write(item.getDue() + "\n");
}
}

private String escapeCsv(String s) {
if (s == null) return "";
boolean needsQuotes =
s.contains(",") || s.contains("\"") || s.contains("\n");

String escaped = s.replace("\"", "\"\"");
return needsQuotes ? "\"" + escaped + "\"" : escaped;
}
}
21 changes: 21 additions & 0 deletions src/main/java/org/example/CSV/saveToFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import org.example.todolist.TodoItem;

import java.io.BufferedWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;

import static java.nio.file.Files.write;

public void saveToFile(List<TodoItem> items, Path path) throws Exception {
try (BufferedWriter writer =
Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
write(items, writer);
}
}

private void write(List<TodoItem> items, BufferedWriter writer) {
}

void main() {

}
8 changes: 7 additions & 1 deletion src/main/java/org/example/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public static int add(int a, int b){

}

public static int add(int a, int b,int c){
public static int add(int a, int b,int c)
{
return a + b + c;
}

public static int add(int... numbers){
int sum = 0;
for(int number : numbers){
Expand All @@ -37,4 +39,8 @@ public static int divide(int a, int b) {
return a / b;
}

public static float divide(float a, float b) {
return a / b;
}

}
7 changes: 7 additions & 0 deletions src/main/java/org/example/price/NotificationService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.price;

public interface NotificationService {

void notify(String productName, int price);
boolean isSent();
}
17 changes: 17 additions & 0 deletions src/main/java/org/example/price/PriceWatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.example.price;

public class PriceWatcher {
Priceservice priceService;
NotificationService notificationService;

PriceWatcher(Priceservice priceService, NotificationService notificationService){
this.priceService = priceService;
this.notificationService = notificationService;
}
public void checkPrices(){
int price = priceService.getPrice("T-SHIRT");
if (price < 100)
notificationService.notify("T-SHIRT", priceService.getPrice("T-SHIRT"));

Check warning on line 14 in src/main/java/org/example/price/PriceWatcher.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Suspicious indentation after control statement without braces

Suspicious indentation after 'if' statement

}
}
7 changes: 7 additions & 0 deletions src/main/java/org/example/price/Priceservice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.price;

public interface Priceservice {
int getPrice(String productName);


}
21 changes: 21 additions & 0 deletions src/main/java/org/example/socket/SimpleClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.example.socket;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

public class SimpleClient {

static void main(){
int port = 3000;
String serverIp = "127.0.0.1";

try(Socket socket = new Socket(serverIp, port)){

Check warning on line 13 in src/main/java/org/example/socket/SimpleClient.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Empty 'try' block

Empty `try` block

} catch (UnknownHostException e){
throw new RuntimeException(e);
} catch (IOException e){
throw new RuntimeException(e);
}
}
}
52 changes: 52 additions & 0 deletions src/main/java/org/example/socket/SimpleServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.example.socket;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;

public class SimpleServer {

static void main(){

int port = 3000;

try(ServerSocket serverSocket = new ServerSocket(port, 5,
InetAddress.ofLiteral("127.0.0.1"))){
System.out.println("" + serverSocket.getLocalPort() + " is the port");

while(true) {

Check warning on line 19 in src/main/java/org/example/socket/SimpleServer.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Infinite loop statement

`while` statement cannot complete without throwing an exception
Socket socket = serverSocket.accept();
Thread.ofVirtual().start(() -> {
try {
handleClient(socket);
} catch (IOException e) {
throw new RuntimeException(e);
}
});

}
} catch (IOException e) {
throw new RuntimeException(e);
}

}

private static void handleClient(Socket socket ) throws IOException {
try (Socket client = socket) {
System.out.println("Client connected: " + socket.getRemoteSocketAddress());
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
PrintWriter writer = new PrintWriter(output, true);
IO.readln();

writer.println("Hello client!");
socket.close();
} catch(IOException e) {
throw new RuntimeException(e);
}
}
}

18 changes: 18 additions & 0 deletions src/main/java/org/example/toDoList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.example;
//
public class toDoList {


private int nextId = 1;


public TodoItem add(String text) {
return new TodoItem(nextId++);
}

public int size(int size){
return size = 0;

Check warning on line 14 in src/main/java/org/example/toDoList.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Unused assignment

The value `0` assigned to `size` is never used
}

}

47 changes: 47 additions & 0 deletions src/main/java/org/example/todolist/TodoItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.example.todolist;

import java.time.LocalDate;
import java.time.LocalDateTime;

public class TodoItem {
private final int id;
private final String task;
private final LocalDate due;
private boolean done;


public TodoItem(int id, String task, LocalDate due) {
this.id = id;
this.task = task;
this.due = due;
this.done = done;

Check notice on line 17 in src/main/java/org/example/todolist/TodoItem.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Constant values

Value `done` is always 'false'

Check warning on line 17 in src/main/java/org/example/todolist/TodoItem.java

View workflow job for this annotation

GitHub Actions / Qodana for JVM

Nullability and data flow problems

Variable is already assigned to this value
}



public int getId() {
return id;
}

public String getTask() {
return task;
}

public LocalDate getDue() {

return due;

}
@Override
public String toString() {
return "Id: " + id;
}

public boolean isDone() {
return done;
}

public void markDone() {
done = true;
}
}
Loading
Loading