Skip to content

Ateeb #55

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

Open
wants to merge 2 commits into
base: main
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
33 changes: 33 additions & 0 deletions src/main/java/com/booleanuk/core/Admin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.booleanuk.core;

public class Admin {
protected String title;
boolean onLoan = false;
public Admin(String title){
this.title = title;

}
public boolean isOnLoan() {

return onLoan;
}

public String checkIn() {
if (!this.isOnLoan()) {
return "item is not currently on loan";
}
this.onLoan = false;
return "item has been checked in";
}


public String checkOut() {
if (this.isOnLoan()) {
return "item is currently on loan";
}

this.onLoan = true;

return "item has been checked out";
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/Bike.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class Bike extends Vehicle{
public Bike(int topSpeed){
super(topSpeed);
}
}
29 changes: 2 additions & 27 deletions src/main/java/com/booleanuk/core/Book.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
package com.booleanuk.core;

public class Book {
String title;

boolean onLoan = false;

public class Book extends Admin{
public Book(String title) {
this.title = title;
}

public boolean isOnLoan() {
return onLoan;
super(title);
}

public String checkIn() {
if (!this.isOnLoan()) {
return "item is not currently on loan";
}

this.onLoan = false;

return "item has been checked in";
}

public String checkOut() {
if (this.isOnLoan()) {
return "item is currently on loan";
}

this.onLoan = true;

return "item has been checked out";
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/booleanuk/core/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.booleanuk.core;

public class Car extends Vehicle{
String transmissionType;
public Car(int topSpeed, String transmissionType){
super(topSpeed);
this.transmissionType = transmissionType;
}
public String move(){
System.out.println("In the override move method in car");
return "Moving at: " + this.getTopSpeed() + " using a " + this.transmissionType +" transmission Type";
}

}
75 changes: 13 additions & 62 deletions src/main/java/com/booleanuk/core/Library.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,26 @@
package com.booleanuk.core;

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

public class Library {
List<Article> articles;
List<Book> books;
List<Newspaper> newspapers;
public class Library{
List<Admin> items = new ArrayList<>();

public void addToStock(Article item) {
this.articles.add(item);
}
public Library() {

public void addToStock(Book item) {
this.books.add(item);
}

public void addToStock(Newspaper item) {
this.newspapers.add(item);
public void addToItem(Admin item) {
this.items.add(item);
}

// The following methods may contain code that you are unfamiliar with. The strange syntax of article -> something
// is called a lambda expression (https://www.w3schools.com/java/java_lambda.asp)
public String checkInArticle(String title) {
List<Article> filtered = this.articles.stream()
.filter(article -> article.title.equals(title))
.toList();

if (filtered.size() < 1) {
return "item is not part of the library's collection";
}

return filtered.get(0).checkIn();
}

public String checkOutArticle(String title) {
List<Article> filtered = this.articles.stream()
.filter(article -> article.title.equals(title))
.toList();

if (filtered.size() < 1) {
return "item is not part of the library's collection";
}
public String checkInItem(String title) {

return filtered.get(0).checkOut();
}

public String checkInBook(String title) {
List<Book> filtered = this.books.stream()
.filter(book -> book.title.equals(title))
List<Admin> filtered = this.items.stream()
.filter(item -> item.title.equals(title))
.toList();

if (filtered.size() < 1) {
Expand All @@ -57,33 +30,10 @@ public String checkInBook(String title) {
return filtered.get(0).checkIn();
}

public String checkOutBook(String title) {
List<Book> filtered = this.books.stream()
.filter(book -> book.title.equals(title))
.toList();

if (filtered.size() < 1) {
return "item is not part of the library's collection";
}

return filtered.get(0).checkOut();
}

public String checkInNewspaper(String title) {
List<Newspaper> filtered = this.newspapers.stream()
.filter(newspaper -> newspaper.title.equals(title))
.toList();

if (filtered.size() < 1) {
return "item is not part of the library's collection";
}

return filtered.get(0).checkIn();
}

public String checkOutNewspaper(String title) {
List<Newspaper> filtered = this.newspapers.stream()
.filter(newspaper -> newspaper.title.equals(title))
public String checkOutItem(String title) {
List<Admin> filtered = this.items.stream()
.filter(item -> item.title.equals(title))
.toList();

if (filtered.size() < 1) {
Expand All @@ -92,4 +42,5 @@ public String checkOutNewspaper(String title) {

return filtered.get(0).checkOut();
}

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

public class Main {
public static void main(String[] args) {
Vehicle[] vehicles = {new Car(120, "Manual"), new Plane(20), new Bike(50)};

//Vehicle vehicle = new Vehicle(1);

Vehicle singleVehicle = new Vehicle(111);

for (Vehicle vehicle : vehicles) {
System.out.println(vehicle.move());

}

//System.out.println("Vehicle "+ vehicle.move());
}
}
19 changes: 2 additions & 17 deletions src/main/java/com/booleanuk/core/Newspaper.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
package com.booleanuk.core;

public class Newspaper {
String title;

boolean onLoan = false;

public class Newspaper extends Admin {
public Newspaper(String title) {
this.title = title;
}

public boolean isOnLoan() {
return onLoan;
}

public String checkIn() {
return "newspapers are not available for loan";
}

public String checkOut() {
return "newspapers are not available for loan";
super(title);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/booleanuk/core/Plane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.booleanuk.core;

import java.sql.SQLOutput;

public class Plane extends Vehicle{
public Plane(int topSpeed){
//dette vil forstyrre koden din, og gi deg feilmelding
//System.out.println("Hello");
super(topSpeed);
}
public Plane(){
super(1000);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/booleanuk/core/SomeRandom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.booleanuk.core;

public class SomeRandom {
public SomeRandom(){
Car car = new Car(100,"ff");

System.out.println(car.topSpeed);
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/booleanuk/core/Vehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.booleanuk.core;

public class Vehicle {
protected int topSpeed;

public Vehicle(int topSpeed){
this.topSpeed = topSpeed;
}
public String move(){
System.out.println("In the base class move method");
return "movin at:" + this.topSpeed;
}

public int getTopSpeed() {
return topSpeed;
}

public void setTopSpeed(int topSpeed) {
this.topSpeed = topSpeed;
}

public String wheels(){
return "";
}
}
18 changes: 18 additions & 0 deletions src/test/java/com/booleanuk/core/LibraryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class LibraryTest {
@Test
public void shouldBeUnavailableForCheckIn() {

Library library = new Library();
Newspaper news = new Newspaper("hei");
library.addToItem(news);
news.checkOut();

Assertions.assertEquals("item has been checked in", library.checkInItem("hei"));
}

}
4 changes: 2 additions & 2 deletions src/test/java/com/booleanuk/core/NewspaperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class NewspaperTest {
@Test
public void shouldBeUnavailableForCheckIn() {
Newspaper newspaper = new Newspaper("The Daily Java");
Assertions.assertEquals("newspapers are not available for loan", newspaper.checkIn());
Assertions.assertEquals("item is not currently on loan", newspaper.checkIn());
}

@Test
public void shouldBeUnavailableForCheckOut() {
Newspaper newspaper = new Newspaper("The Daily Java");
Assertions.assertEquals("newspapers are not available for loan", newspaper.checkOut());
Assertions.assertEquals("item has been checked out", newspaper.checkOut());
}
}