0% found this document useful (0 votes)
66 views7 pages

CS211 Fall 2002 P4

This document provides instructions for Project 4, which involves creating classes for storing and managing a game catalog using object-oriented programming with exceptions, generics, and collections. Students must create Java classes including Game, Format, VideoGame, FirstPartyVideoGame, SecondPartyVideoGame, ThirdPartyVideoGame, and ReleasedGame based on the specifications provided. The project is due November 4th and involves individual implementation, testing, and submission of the project files through Blackboard along with verification steps to ensure correct submission. The classes will be graded based on implementation and passing automated and manual tests.

Uploaded by

Nikhil Varandani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views7 pages

CS211 Fall 2002 P4

This document provides instructions for Project 4, which involves creating classes for storing and managing a game catalog using object-oriented programming with exceptions, generics, and collections. Students must create Java classes including Game, Format, VideoGame, FirstPartyVideoGame, SecondPartyVideoGame, ThirdPartyVideoGame, and ReleasedGame based on the specifications provided. The project is due November 4th and involves individual implementation, testing, and submission of the project files through Blackboard along with verification steps to ensure correct submission. The classes will be graded based on implementation and passing automated and manual tests.

Uploaded by

Nikhil Varandani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

GMU Fall 2022 – CS 211 – Project 4

Due Date: Friday, November 4th, 11:59pm

Changelog
• Nothing yet!

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 the 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.

Submission
Submission instructions are as follows:

1. Let xxx be your lab section number and let yyyyyyyy be your GMU userid. Create the directory
xxx_yyyyyyyy_P4
2. Place your files in the directory you've just created
3. Create the file ID.txt in the format shown below, containing your name, userid, G#, lecture section
and lab section, and add it to the directory.
Full Name: George Mason
userID: gmason
G#: 01234567
Lecture section: 001
Lab section: 201
4. Compress the folder and its contents into a .zip file and upload the file to Blackboard.
5. Upload a backup of the .zip file to OneDrive
6. Download the files you uploaded to Blackboard and OneDrive, unzip them, recompile and test
them, in order to verify that they are both correct.
If you skip steps 5 and 6 and your submission is wrong and/or files are missing from it, you will
get zero points and there will be no excuse!

Grading
The implementation of each class is worth the points specified at the beginning of each section. We will
use both automated testing and manual inspection for the grading. Partial credit is possible but do not
count on it if your code does not pass any tests. Hard coding to pass a certain set of test cases will receive
an automatic zero.

WARNING: Programs that do not compile will receive a zero.


Testing
You will be programming without a tester. The goal is to help you put more focus on writing logically
correct programs instead of trying to pass certain tests only.

Before using any tester, make sure you always compile and run your code without the tester to verify
that there are no syntax errors. It is expected and helpful to write JUnit tests for running some basic
tests on your own. From now on, place your debugging logic (static main methods) into a tester (e.g.,
P4Tester.java).

On Windows:

javac -cp .;junit-cs211.jar *.java


java -cp .;junit-cs211.jar P4Tester

On Mac or Linux:
javac -cp .:junit-cs211.jar *.java
java -cp .:junit-cs211.jar P4Tester

Note: all the required classes and public members must exist for the grading tester to compile
successfully. If you would like to test your code before you have implemented everything, make sure you
have at least created the appropriate files and included the necessary members (fields and methods),
even if their implementation is not complete.

Tasks
You must implement the following classes based on the specification provided. Be reminded that it is
very important to follow these specs, otherwise your code will not compile/run with the tester. If you get
warnings from the compiler, do not ignore them.
[10pts] Game class
This is an abstract class for representing different kinds of games (videogames, table-top games, etc.).
All the games in the game catalog will be descendants of this class. It should implement the Comparable
interface and specify the generic type for that interface so that Game can be compared to another Game.
However, the details of the compareTo method should be left to subclasses.

• puc: A string representing the Product Unique Code (PUC) of this game. Should have a getter
(final) but no setter.
• genres: A collection of strings representing the genres of this game. Should have a getter (final)
but no setter. Such strings are unique within the collection. At least one genre must be provided.
• getType(): A method that will return a string representing the type of this game. The details of
this method should be left to subclasses.
• Game(puc, genres): constructor with two arguments. Initializes private fields.
• equals(obj): Overrides parent to return true if the given object is also a game, and their PUCs
match. Otherwise, return false.
• toString(): returns a string representation of this game. This should have the form "Type: type,
PUC: puc, Genres: genres", replacing the italicized placeholders with the string returned by getType,
puc, and genres values.

Collections such as genres must be formatted using Arrays.deepToString().

Spacing, spelling, and capitalization are all important. Carefully implementing this method
will allow for significant code reuse in subclasses.

[5pts] Format enumeration


This is an enumeration representing the different formats a videogame can be distributed. It should
have the following options:

• CARTRIDGE
• CD
• MINIDISC
• BLURAY
• DOWNLOAD
• CLOUD

[10pts] Videogame class


This is an abstract subclass of Game that represents different types of videogames. It has a constructor,
toString(), and provides an implementation for compareTo().

• publisher: A string with the name of the publisher. Should have a getter (final) but no setter.
• director: A string with the name of the director. Should have a getter (final) but no setter.
• formats: A collection of instances of the Format enum (described above). Should have a getter
(final) but no setter. Such instances are unique within the collection. At least one format must be
provided.
• developers: A collection of strings with the names of the studios that developed the videogame.
Should have a getter (final) but no setter. The order of developers indicates their contribution
efforts, it must be preserved.
• title: A string with the title of the videogame. Should have a getter (final) but no setter.
• year: An integer representing the year the videogame was released. Should have a getter (final)
but no setter.
• Videogame (puc, genres, publisher, director, formats, developers, title, year): A constructor
which sets the private fields. Must call the parent class constructor.
• toString(): A string representation of this object. Has the form "Publisher: producer, director: director,
formats: formats, developers: developers, Title: title, year: year, " followed by the information given by
its parent’s toString() method. Consider how inheritance can enable code reuse in this method.
Collections such as formats and developers must be formatted using Arrays.deepToString().

• compareTo(argument): This method returns an integer value representing whether the instance
given as an argument should be ordered before or after the calling instance. Negative numbers
indicate the calling instance (this) should be ordered first. Positive numbers indicate the
argument should be ordered first. Zero indicates that both instances have the same ordering.
This method is what is used to sort collections in the collections framework. See the description
of the sort() method in the GameCatalog class for how this method should be implemented.

[5pts] FirstPartyVideogame class


This is a concrete class that inherits from VideoGame and represents first-party games. It overrides the
constructor, and getType() methods.

• getType(): Returns the string "First-Party".


• FirstPartyVideogame(puc, genres, publisher, director, formats, developers, title, year):
Calls the parent class constructor with the given arguments.

[5pts] SecondPartyVideogame class


This is a concrete class that inherits from VideoGame and represents first-party games. It overrides the
constructor, and getType() methods.

• getType(): Returns the string "Second-Party".


• SecondPartyVideogame(puc, genres, publisher, director, formats, developers, title, year):
Calls the parent class constructor with the given arguments.

[5pts] ThirdPartyVideogame class


This is a concrete class that inherits from VideoGame and represents first-party games. It overrides the
constructor, and getType() methods.

• getType(): Returns the string "Third-Party".


• ThirdPartyVideogame(puc, genres, publisher, director, formats, developers, title, year):
Calls the parent class constructor with the given arguments.

[10pts] ReleasedGame class


This is a generic class, with two type specifications, that represents a mapping between keys and values.
The first type can be any type, the second type must implement the Comparable interface and be
comparable to other instances of the same type. The Releasedgame class itself should also implement
Comparable, such that ReleasedGame instances are comparable to other ReleasedGame instances of the
same kind (same generic type specifiers). The specific syntax for this class declaration should be:

public class ReleasedGame <K,V extends Comparable<V>> implements Comparable<


ReleasedGame <K,V>>

• key: A reference of the first generic type. Should have a getter but no setter.
• value: A reference of the second generic type. Should have a getter but no setter.
• ReleasedGame(key, value): A constructor which sets the private data members.
• equals(obj): Overrides the parent’s method to return true if the other object is also a ReleasedGame
and has the same value. Otherwise, returns false.
• compareTo(...): Returns the result of comparing the value field. If the generic specification is
correct, there should be no need to cast anything.

[5pts] Searchable interface


This interface contains a single method, matches, which returns true if a given game matches the criteria
of this search.

• matches(ReleasedGame<String, Game>): this is the method that will be called by the game
catalog when searching. Items which return true will be included, items which return false will not
be.

[10pts] GameSearcher class


This is a concrete class that implements the Searchable interface, and represents a search with multiple
terms, matching games which contain a given search strings among their fields.

• searchTerms: a collection of strings to search for in each released game. No getters or setters.
• GameSearcher(searchTerms): constructor that takes a collection of strings and should set
searchTerms.
• matches(ReleasedGame<String, Game>): returns true if the released game contains any of the
search terms. Consider using the string returned by the toString method of the Game class. You
may find the string method indexOf useful as well.

[10pts] GameCatalog class


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.

• catalog: 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<String, Game>). Should have a getter (final), no setter.
• GameCatalog (): A default constructor which initializes the catalog.
• add(puc, game): 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<String, Game> instance with the
given data.
• search(searchable): 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.
• sort(): This method sorts (ascending) the field catalog according to the following rules:
1. First-party videogames come before second-party videogames, second-party videogames
come before third-party videogames.
2. First-party videogames are sorted first by year, then by title.
3. Second-party videogames are sorted first by year, then by number of developers.
4. Third-party videogames are sorted first by year, then by director, then by number of
formats.
This can be implemented briefly if the compareTo(...) method is correctly implemented in the
subclasses of Game and in VideoGame. The Collections class has a static method sort(...), which will
automatically sort using the compareTo(...) method of the elements stored in the in the list passed
as argument. The logic for each compareTo method should first check the type (using instanceof) of
the argument, then compare the appropriate strings using their own compareTo (the class String
already implements compareTo). As mentioned in the Videogame class, a negative value indicates
the calling instance should come first, a positive value indicates the calling instance should come
second, and zero indicates they have the same ordering.

[10pts] VideoGameException class


This is an exception that inherits from Exception and represents situations where:

The constructor of a videogame receiving arguments that are null, empty collections, collections
with null values, or for the case of year to be before 1977 or after 2077.

The exception must implement:

• fieldName: A string that stores the name of the null or illegal argument, it must match the name
of the field that it was trying to set. Should have a getter but no setter.
• VideoGameException(fieldName): Constructor which sets the private field and calls the parent
class constructor with the message "an argument has null or illegal values.".

[10pts] VideoGameDeveloperException class


This is an exception that inherits from IllegalArgumentException and represents situations where:

First-party videogames being added to the game catalog that have more than one developer, or the
developer’s name is not same as the publisher.

Second-party videogames being added to the game catalog, whose developers has published
videogames as a third-party at least two years before.

Third-party videogames being added to the game catalog, whose developers has published
videogames as a first-party. Take that Sega!

The exception must implement:


• developer: a string with the name of the developer causing the exception.
• videogame: A reference to the videogame trying to be added. Should have a getter but no setter.
• VideoGameDeveloperException(developer, videogame): Constructor which sets the private
fields, and calls the parent class constructor with the message "a developer is preventing adding the
videogame to the catalog.".

[5pts] GameCatalogException class


This is an exception that inherits from IllegalStateException and represents the situation where:

A game being added to the released game catalog, which UPC is already present in the catalog.

The exception must implement:

• upc: A string that stores the UPC of the duplicate game that was being added. Should have a
getter but no setter.
• game: A reference to the duplicate game. Should have a getter but no setter.
• GameCatalogException(upc, game): Constructor which sets the private fields, and calls the
parent class constructor with the message "the game’s UPC is already in the catalog.".

You might also like