+1 (315) 557-6473 

Program To Create a Set of Classes for Storing and Managing a Game Catalog Using Java Programming Language Assignment Solutions.


Instructions

Objective
Write a program to create a set of classes for storing and managing a game catalog in Java programming language.

Requirements and Specifications

Description
The purpose of this assignment is to practice OOP with exceptions, generics, and collections. Your task is to create a set of classes for storing and managing a game catalog. This will require an understanding of exceptions, generics, and the Java collections framework.
Overview
  1. Create the Java classes, interfaces, and enumerations described below. Each should be in its own .java file.
  2. Implement the methods and fields described.
  3. Test your code for correctness.
  4. Prepare to complete the java assignment for submission and submit it through Blackboard.
Rules
  1. This project is an individual effort, the Honor Code applies.
  2. You may import the following classes only: List, LinkedList, ArrayList, HashSet, EnumSet, Arrays, Collections.
  3. Comment your code in javadoc style, especially any parts that is not obvious what you are doing.
  4.  Class fields should not be visible to other classes (unless otherwise noted). Create getter methods if necessary.
  5. You may add your own methods, but they must be declared private. No additional fields are allowed.
Source Code
import java.util.*;
/**
 * This class represents the catalog of released games. It contains a list of games and provides methods
 * for games with the UPC it has been released with, returning a subset of items in the catalog given some
 * search terms, and sorting the catalog.
 */
public class GameCatalog {
    /**
     * A list of released games. A released game is an instance of the ReleasedGame class with
     * the first type specified to be a string, and the second type specified to be Game (ReleasedGame).
     */
    private final List> catalog;
    /**
     * A default constructor which initializes the catalog.
     */
    public GameCatalog() {
        catalog = new ArrayList<>();
    }
    /**
     * Getter for catalog field
     * @return inner game collection
     */
    public List> getCatalog() {
        return catalog;
    }
    /**
     * A method for adding games to the catalog. The first argument is a string, the second the game.
     * This method should create a new ReleasedGame instance with the given data.
     * @param puc Product Unique Code of new game
     * @param game Game instance to add
     */
    public void add(String puc, Game game) {
        if (catalog.stream().anyMatch(rg -> rg.getKey().equals(puc))) {
            throw new GameCatalogException(puc, game);
        }
        if(game instanceof FirstPartyVideogame) {
            FirstPartyVideogame firstPartyVideogame = (FirstPartyVideogame) game;
            Collection developers = firstPartyVideogame.getDevelopers();
            if (developers.size() != 1 || !developers.iterator().next().equals(firstPartyVideogame.getPublisher())) {
                throw new VideogameDeveloperException(Arrays.deepToString(developers.toArray()), firstPartyVideogame);
            }
        }
        if(game instanceof SecondPartyVideogame) {
            SecondPartyVideogame secondPartyVideogame = (SecondPartyVideogame) game;
            int year = secondPartyVideogame.getYear();
            Collection developers = secondPartyVideogame.getDevelopers();
            for (String developer : developers) {
                if (catalog.stream().filter(rg -> (rg.getValue()) instanceof ThirdPartyVideoGame)
                        .map(rg -> (ThirdPartyVideoGame)rg.getValue())
                        .anyMatch(tpvg -> tpvg.getDevelopers().contains(developer) && year - tpvg.getYear() >= 2)) {
                    throw new VideogameDeveloperException(developer, secondPartyVideogame);
                }
            }
        }
        if(game instanceof ThirdPartyVideoGame) {
            ThirdPartyVideoGame thirdPartyVideoGame = (ThirdPartyVideoGame) game;
            Collection developers = thirdPartyVideoGame.getDevelopers();
            for (String developer : developers) {
                if (catalog.stream().filter(rg -> (rg.getValue()) instanceof FirstPartyVideogame)
                        .map(rg -> (FirstPartyVideogame)rg.getValue())
                        .anyMatch(fpvg -> fpvg.getDevelopers().contains(developer))) {
                    throw new VideogameDeveloperException(developer, thirdPartyVideoGame);
                }
            }
        }
        catalog.add(new ReleasedGame<>(puc, game));
    }
    /**
     * This method creates and returns a new list of released games.
     * This new list should contain all released games from the catalog for which the given searchable's matches method returns true.
     * @param searchable searhable instance to be used for search
     * @return search result list
     */
    public List> search(Searchable searchable) {
        List> result = new ArrayList<>();
        for(ReleasedGame game : catalog) {
            if (searchable.matches(game)) {
                result.add(game);
            }
        }
        return result;
    }
    /**
     * This method sorts (ascending) the field catalog according to the required rules.
     */
    public void sort() {
        Collections.sort(catalog);
    }
}