LAB#SE00-1: Maven Person

javase
lab

Maven Person

Basic understanding of Java programming language is required, as well as some familiarity with Maven or Gradle for managing dependencies and building the project. ssl encryption and is intended to run behind a Knowledge of algotighms and data structures to implement the required classes.

Create multiple classes in Java (Person, Student, Book, Car and Author) using the most convenient entity relationship between them.

Test these classes using JUnit.

  1. Create a new Maven or Gradle project and setting up the project structure
  2. Modify the project’s pom.xml or build.gradle file to import necessary dependencies, including JUnit for testing
  3. Implement the required classes in Java
  4. Implement two basic patter-designs: singleton and think about factory
  5. Write JUnit tests to verify that classes work as expected
  • Allow the user to input data via the console, rather than using hard-coded test data in JUnit tests

Approach 1

UML diagram

TODO

Pending to create UML diagram

Classes specifications

Person

Person.java
package org.labse00part1.domain;

import lombok.*;

@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Person {
    private String firstName;
    private String lastName;
    private int age;
}

Student

Student.java
package org.labse00part1.domain;

import lombok.*;

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

@Data
@Getter
@Setter
@NoArgsConstructor
@ToString(callSuper=true)
public class Student extends Person{
    private String university;
    private List<Book> books;

    private Car car;

    @Builder
    public Student(String firstName, String lastName, int age, String university) {
        super(firstName, lastName, age);
        this.university = university;
        this.books = new ArrayList<>();
        this.car = new Car();
    }

    @Builder
    public Student(String firstName, String lastName, int age, String university, List<Book> books) {
        super(firstName, lastName, age);
        this.university = university;
        this.books = books;
        this.car = new Car();
    }

    @Builder
    public Student(String firstName, String lastName, int age, String university, List<Book> books, Car car) {
        super(firstName, lastName, age);
        this.university = university;
        this.books = books;
        this.car = car;
    }

    public void addBook(Book newBook) {
        this.books.add(newBook);
    }
}

Author

Author.java
package org.labse00part1.domain;

import lombok.*;

@Data
@Getter
@Setter
@NoArgsConstructor
@ToString(callSuper=true)
public class Author extends Person{
    private String genre;

    @Builder
    public Author(String firstName, String lastName, int age, String genre) {
        super(firstName, lastName, age);
        this.genre = genre;
    }
}

Car

Car.java
package org.labse00part1.domain;

import lombok.*;

@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Car {
    public int doors;
    public int seats;
    public String color;
}

Book

Book.java
package org.labse00part1.domain;

import lombok.*;

@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Book {
    private String title;
    private int pages;
    private String ISBN;
    private Author author;
}

Tests

Use the Code Coverage feature!

When launching tests, do it with Code Coverage to know how much of your code is being tested. Just click on the button next to the Run one when executing a batch of tests or right-click on the Play button next to each test: IntelliJ - Code Coverage