Concept explainers
Review the UML diagram provided for a game software application. A text version is available: Text Version for UML diagram Word Document. You may notice that it is incomplete - it is missing attributes and methods, and only includes a small portion of a complete game application. This is quite common! As a software developer, typically you will be given pieces of the puzzle or tasks to complete as part of a larger project and as a member of a larger team. It takes practice to focus on the information you are given to determine what you have and what steps you need to take to complete the task.
Specifically, the game application requires that only one instance of the game be able to exist in memory at any given time. This can be accomplished by creating unique identifiers for each instance of the game.
- Complete the UML diagram to accurately represent a singleton pattern for the Game Service class. You should replace the question marks in the UML diagram with appropriate static and instance attributes and/or methods to make the ordinary class into a singleton. You may create the diagram using Lucidchart or a tool of your choice, such as draw.io or Visio. A tutorial for creating UML diagrams is available: Lucidchart Tutorial for Creating Class Diagrams PDF.
- Code below just need help completing the UML chart:
package com.gamingroom;
import java.util.ArrayList;
import java.util.List;
/**
* A singleton service for the game engine
*
* @author coce@snhu.edu
*/
public class GameService {
/**
* A list of the active games
*/
private static List<Game> games = new ArrayList<Game>();
/*
* Holds the next game identifier
*/
private static long nextGameId = 1;
// FIXME: Add missing pieces to turn this class a singleton
private static GameService instance = new GameService();
private void GameService() {
}
public static GameService getInstance() {
return instance;
}
/**
* Construct a new game instance
*
* @param name the unique name of the game
* @return the game instance (new or existing)
*/
public Game addGame(String name) {
// a local game instance
Game game = null;
for (Game currentGame: games) {
if (currentGame.getName().equals(name)) {
return currentGame;
}
}
// if not found, make a new game instance and add to list of games
if (game == null) {
game = new Game(nextGameId++, name);
games.add(game);
}
// return the new/existing game instance to the caller
return game;
}
/**
* Returns the game instance at the specified index.
* <p>
* Scope is package/local for testing purposes.
* </p>
* @param index index position in the list to return
* @return requested game instance
*/
Game getGame(int index) {
return games.get(index);
}
//Returns game instance with specific id
public Game getGame(long id) {
// a local game instance
Game game = null;
// if found, simply assign that instance to the local variable
// If a game with name exists it returns the existing instance without adding to data structure
for (Game currentGame: games) {
if (currentGame.getId() == id) {
return currentGame;
}
}
return game;
}
public Game getGame(String name) {
// a local game instance
Game game = null;
//if a game already exists with this name, return game instance
for (Game currentGame: games) {
if (currentGame.getName().equals(name)) {
game = currentGame;
}
}
return game;
}
/**
* Returns the number of games currently active
*
* @return the number of games currently active
*/
public int getGameCount() {
return games.size();
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps
- Please write a Quality Plan which includes quality assurance and Testing for the computer game clue-less following the instructions below: This game is a simplified version of the popular board game, Clue . The main simplification is in the navigation of the game board. In Clue-Less there are the same nine rooms, six weapons, and six people as in the board game. The rules are pretty much the same except for moving from room to room.arrow_forwardPlease written by computer source Module 4 Assignment This assignment will reinforce your knowledge of the following areas: Coding classes with events Subscribing to and handling events Introduction This phase of the project will have you make some updates to classes in the library project. Defect Management Part of the evaluation of this assignment will include your ability to repair defects from previous versions of your code. Ensure that you are applying the feedback provided to you in the assignment evaluations. You should expect to receive deductions on this assignment for any outstanding defects. Requirements WARNING! It is highly recommended you make a copy of the your RRCAGLibraryFirstNameLastName solution prior to editing the LastName.FirstName.Business project. Update the following classes in the LastName.FirstName.Business namespace. SalesQuote Class Add the following events and methods to the SalesQuote class. Events + VehiclePriceChanged : EventHandler - Occurs when the…arrow_forwardWhat is the proper relationship in a UML Class diagram between a test program and a program?arrow_forward
- Idle thought While building the framework, anticipate issues. After all. This mean? various obstacles as you build the framework. So anything. This mean?arrow_forwardThe scope to use when all modules within the project should have access to the variable without having to share it. Class Local General Blockarrow_forwardScenario: The Best Events Company organizes events, and business is booming, so much so that they need your help to manage their service. They want you to create a software system to manage their employees, clients, suppliers, and events. A part of their software requirement is given below. You are required to do a self-study on how event-organizing companies work and create a design for managing the company's functions. In addition to the requirements below, you are encouraged to add more attributes and functionalities to the system. The company has different types of employees, such as, Sales Managers, Salespersons, Marketing Managers, Marketers, Accountants, Designers and Handymen. Some details required for employees include name, employee ID, department, job title, basic salary, age, date of birth, and passport details are also stored in the system. The table below provides a glimpse of how employees are managed. It is clear from the table that Susan Meyers manages both Shyam…arrow_forward
- A tool suite that primarily supports application development based on specific analysis and design models is sometimes called a(n) _ CASE tool or code generatorarrow_forwardDetermine what documentation a developer should have at the conclusion of a project.arrow_forwardWithout selection structures, programming would not be possible, but these structures are not perfect. Each application must use the same iteration method because there are so many users, online customers, and different kinds of deals. Do people who work in these areas have to follow a certain set of rules? What is it about these buildings that makes them different from others?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education