SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
Here are the instructions and then the code in a sec.
**Please Resubmit the revised and updated Code (GamerService) with Comments added
explaining please. RIGHT***** JAVA. HOWEVER IF YOU NEED TO CHANGE THE
ENTIRE THING IT IS FINE. I AM DESPERATE.
Part II. Java Application: Use the code you submitted in Project One Milestone to continue
developing the game application in this project. Be sure to correct errors and incorporate
feedback before submitting Project One.
Please note: The starter code for this project was provided in the Project One Milestone. If you
have not completed the Project One Milestone, you will not be penalized in this assignment, but
you will have additional steps to complete to ensure you meet all the components of Project One.
Review the class files provided and complete the following tasks to create a functional game
application that meets your clients requirements. You will submit the completed game
application code for review.
Begin by reviewing the base Entity class. It contains the attributes id and name, implying that all
entities in the application will have an identifier and name.
Software Design Patterns: Review the GameService class. Notice the static variables holding the
next identifier to be assigned for game id, team id, and player id.
Referring back to Project One Milestone, be sure that you use the singleton pattern to adapt an
ordinary class, so only one instance of the GameService class can exist in memory at any given
time. This can be accomplished by creating unique identifiers for each instance of a game, team,
or player.
Your client has requested that the game and team names be unique to allow users to check
whether a name is in use when choosing a team name. Referring back to the Project One
Milestone, be sure that you use the iterator pattern to complete the addGame() and getGame()
methods.
Create a base class called Entity. The Entity class must hold the common attributes and
behaviors (as shown in the UML diagram provided in the Supporting Materials section below).
Refactor the Game class to inherit from this new Entity class.
Complete the code for the Player and Team classes. Each class must derive from the Entity class,
as demonstrated in the UML diagram.
Every team and player must have a unique name by searching for the supplied name prior to
adding the new instance. Use the iterator pattern in the addTeam() and addPlayer() methods.
Functionality and Best Practices
Once you are finished coding, use the main() method provided in the ProgramDriver class to run
and test the game application to ensure it is functioning properly.
Be sure your code demonstrates industry standard best practices to enhance the readability of
your code, including appropriate naming conventions and in-line comments that describe the
functionality.
Here is my answer that I need a little improvement on its code since I am having trouble making
it right.
Here I am attaching code for these Files:
Entity.java
Game.java
Team.java
Player.java
GameService.java
ProgramDriver.java
SingletonTester.java
Source Code for Entity.java
package com.gamingroom;
public abstract class Entity implements Comparable {
private long id;
private String name;
/*
* Constructor with an identifier and name
*/
public Entity(long id, String name) {
this.id = id;
this.name = name;
}
/*
* @return id
*/
public long getId() {
return id;
}
/*
* @return name
*/
public String getName() {
return name;
}
@Override
public String toString() {
return "Entity [id=" + id + ", name=" + name + "]";
}
@Override
public int compareTo(Entity other) {
return Long.compare(this.id, other.id);
}
}
Source Code for Game.Java
package com.gamingroom;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Game extends Entity {
private static List teams = new ArrayList<>();
/*
* Constructor with an identifier and name
*/
public Game(long id, String name) {
super(id, name);
}
public Team addTeam(String name) {
Iterator teamIterator = teams.iterator();
while (teamIterator.hasNext()) {
Team team = teamIterator.next();
if (name.equalsIgnoreCase(team.getName())) {
return team;
}
}
Team team = new Team(teams.size(), name);
teams.add(team);
return team;
}
@Override
public String toString() {
return "Game [id=" + getId() + ", name=" + getName() + "]";
}
}
Source Code For Team Java
package com.gamingroom;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Team extends Entity {
private static List players = new ArrayList<>();
/*
* Constructor with an identifier and name
*/
public Team(long id, String name) {
super(id, name);
}
public Player addPlayer(String name) {
Iterator playerIterator = players.iterator();
while (playerIterator.hasNext()) {
Player player = playerIterator.next();
if (name.equalsIgnoreCase(player.getName())) {
return player;
}
}
Player player = new Player(players.size(), name);
players.add(player);
return player;
}
@Override
public String toString() {
return "Team [id=" + getId() + ", name=" + getName() + "]";
}
}
Source Code for PLAYER JAVA
package com.gamingroom;
public class Player extends Entity {
/*
* Constructor with an identifier and name
*/
public Player(long id, String name) {
super(id, name);
}
@Override
public String toString() {
return "Player [id=" + getId() + ", name=" + getName() + "]";
}
}
Source Code for Game Service
package com.gamingroom;
import java.util.ArrayList;
import java.util.List;
/**
* A singleton service for the game engine
*
* @author Bryan Molina******
*/
public class GameService {
/**
* A list of the active games
*/
private static List games = new ArrayList();
/*
* Holds the next game identifier
*/
private static long nextGameId = 1;
private static long nextTeamId = 1;
private static long nextPlayerId = 1;
// Creating a local instance of this class. Since our constructor is private,
// we know that we will only have this one instance of this object making it a singleton.
private static GameService instance = new GameService();
// it is normal for a singleton to have a private constructor so that we don't make additional
instances outside the class.
private GameService() {
}
//Public accessor for our instance will allow outside classes to access objects in this Singleton
Class
public static GameService getInstance() {
return instance;
}
//This is the new line for the assignment ** Bryan Molina
/**
* 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(int i = 0; i < getGameCount(); ++i ) {
if (name.equalsIgnoreCase(games.get(i).getName())) {
game = games.get(i);
}
}
if (game == null) {
game = new Game(nextGameId++, name);
games.add(game);
}
return game;
}
Game getGame(int index) {
return games.get(index);
}
/**
* Returns the game instance with the specified id.
*
* @param id unique identifier of game to search for
* @return requested game instance
*/
public Game getGame(long id) {
// a local game instance
Game game = null;
// FIXME: Use iterator to look for existing game with same id
// if found, simply assign that instance to the local variable
for (int i = 0; i < getGameCount(); ++i) {
if (games.get(i).getId() == id) {
game = games.get(i);
}
}
return game;
}
/**
* Returns the game instance with the specified name.
*
* @param name unique name of game to search for
* @return requested game instance
*/
public Game getGame(String name) {
// a local game instance
Game game = null;
// FIXME: Use iterator to look for existing game with same name
// if found, simply assign that instance to the local variable
for(int i = 0; i< getGameCount(); ++i ) {
if(name.equalsIgnoreCase(games.get(i).getName())) {
game = games.get(i);
}
}
Source Code for Program Driver Java
package com.gamingroom;
/**
* Application start-up program
*
* @author Bryan Molina ***
*/
public class ProgramDriver {
/**
* The one-and-only main() method
*
* @param args command line arguments
*/
public static void main(String[] args) {
// FIXME: obtain reference to the singleton instance
GameService service = GameService.getInstance();
System.out.println("nAbout to test initializing game data...");
// initialize with some game data
Game game1 = service.addGame("Game #1");
System.out.println(game1);
Game game2 = service.addGame("Game #2");
System.out.println(game2);
// use another class to prove there is only one instance
SingletonTester tester = new SingletonTester();
tester.testSingleton();
}
}
return game;
}
/**
* Returns the number of games currently active
*
* @return the number of games currently active
*/
public int getGameCount() {
return games.size();
}
public long getNextPlayerId() {
return nextPlayerId++;
}
public long getNextTeamId() {
return nextTeamId++;
}
}
Source Code for SingletonTester JAVA
package com.gamingroom;
/**
* A class to test a singleton's behavior
*
* @author Bryan Molina *****
*/
public class SingletonTester {
public void testSingleton() {
System.out.println("nAbout to test the singleton...");
// FIXME: obtain local reference to the singleton instance
GameService service = GameService.getInstance();
// a simple for loop to print the games
for (int i = 0; i < service.getGameCount(); i++) {
System.out.println(service.getGame(i));
}
}
}
The expectation I would need is this
ProgramDriver (1) [Java Application] CiProgram FilesJavaljdk-19 binljavaw.exe (Mar 18,
2023, 9:32:50 PM - 9:32:52 PM) [pid: 44352] About to test initializing game data... Game [id=1,
name=Game #1] Game [ id =2, name = Game #2] About to test the singleton... Game [ id =1,
name=Game #1] Game [ id =2, name = Game #2]
fun: New Game Service created. About to test initializing game data... Game [id=1, name=Game
#1] Game [id=2, name=Game #2] About to test the singleton... Game Service already
instantiated. Game [id=1, name=Game #1] Game [id=2, name=Game #2] BUILD
SUCCESSFUL (total time: 0 second

Más contenido relacionado

La actualidad más candente

Prepositions In, At, On
Prepositions In, At, OnPrepositions In, At, On
Prepositions In, At, On
Darplay
 
Past simple and past continuous
Past simple and past continuousPast simple and past continuous
Past simple and past continuous
Pepa Mut
 

La actualidad más candente (20)

Question tags
Question tagsQuestion tags
Question tags
 
Group 10 getting things done by david allen summary
Group 10 getting things done by david allen summaryGroup 10 getting things done by david allen summary
Group 10 getting things done by david allen summary
 
Modal Verbs
Modal VerbsModal Verbs
Modal Verbs
 
Power point past continuous!!! .delgado sebastian.! 5°co
Power point   past continuous!!!  .delgado sebastian.!    5°coPower point   past continuous!!!  .delgado sebastian.!    5°co
Power point past continuous!!! .delgado sebastian.! 5°co
 
Time management for college students
Time management for college studentsTime management for college students
Time management for college students
 
Passive voice exercises
Passive voice exercisesPassive voice exercises
Passive voice exercises
 
future tense
future tensefuture tense
future tense
 
Offers, decisions, promises
Offers, decisions, promisesOffers, decisions, promises
Offers, decisions, promises
 
GTD(R) Workshop
GTD(R) WorkshopGTD(R) Workshop
GTD(R) Workshop
 
Prepositions In, At, On
Prepositions In, At, OnPrepositions In, At, On
Prepositions In, At, On
 
Getting Things Done Review and Summary
Getting Things Done Review and SummaryGetting Things Done Review and Summary
Getting Things Done Review and Summary
 
Past continuous tense by Othman ALRashid
Past continuous tense by Othman ALRashidPast continuous tense by Othman ALRashid
Past continuous tense by Othman ALRashid
 
Prepositions of time: at, in, on
Prepositions of time: at, in, onPrepositions of time: at, in, on
Prepositions of time: at, in, on
 
Present Perfect vs Past Simple : English Language
Present Perfect vs Past Simple : English LanguagePresent Perfect vs Past Simple : English Language
Present Perfect vs Past Simple : English Language
 
THE WEATHER
THE WEATHERTHE WEATHER
THE WEATHER
 
Past simple and past continuous
Past simple and past continuousPast simple and past continuous
Past simple and past continuous
 
Grammar: verb tenses
Grammar: verb tensesGrammar: verb tenses
Grammar: verb tenses
 
Simple past presentation in english
Simple past presentation in englishSimple past presentation in english
Simple past presentation in english
 
Past Progressive
Past ProgressivePast Progressive
Past Progressive
 
Present perfect simple vs past simple
Present perfect simple vs past simplePresent perfect simple vs past simple
Present perfect simple vs past simple
 

Similar a Here are the instructions and then the code in a sec. Please R.pdf

I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
aggarwalshoppe14
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdf
aggarwalshoppe14
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
udit652068
 
Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdf
adwitanokiastore
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
EvanpZjSandersony
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
vishalateen
 
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdfUse Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
ashishgargjaipuri
 
VideoGamepublic class VideoGam.pdf
VideoGamepublic class VideoGam.pdfVideoGamepublic class VideoGam.pdf
VideoGamepublic class VideoGam.pdf
annaistrvlr
 
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdfSuggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
ssuser58be4b1
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdf
anithareadymade
 
31 Coach class For this class you only need to implement .pdf
31 Coach class  For this class you only need to implement .pdf31 Coach class  For this class you only need to implement .pdf
31 Coach class For this class you only need to implement .pdf
AASTHASTYLETRADITION
 
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
rozakashif85
 

Similar a Here are the instructions and then the code in a sec. Please R.pdf (20)

I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdf
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
Thanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdfThanks so much for your help. Review the GameService class. Noti.pdf
Thanks so much for your help. Review the GameService class. Noti.pdf
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
 
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdfUse Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
Use Netbeans to copy your last lab (Lab 07) to a new project called La.pdf
 
VideoGamepublic class VideoGam.pdf
VideoGamepublic class VideoGam.pdfVideoGamepublic class VideoGam.pdf
VideoGamepublic class VideoGam.pdf
 
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdfSuggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
Suggestion- Use Netbeans to copy your last lab (Lab 07) to a new proje.pdf
 
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdf
 
Annotation processor and compiler plugin
Annotation processor and compiler pluginAnnotation processor and compiler plugin
Annotation processor and compiler plugin
 
31 Coach class For this class you only need to implement .pdf
31 Coach class  For this class you only need to implement .pdf31 Coach class  For this class you only need to implement .pdf
31 Coach class For this class you only need to implement .pdf
 
L10 Using Frameworks
L10 Using FrameworksL10 Using Frameworks
L10 Using Frameworks
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docx
 
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdfWrite a class (BasketballTeam) encapsulating the concept of a tea.pdf
Write a class (BasketballTeam) encapsulating the concept of a tea.pdf
 
Creating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdfCreating a Facebook Clone - Part X - Transcript.pdf
Creating a Facebook Clone - Part X - Transcript.pdf
 
Java oops features
Java oops featuresJava oops features
Java oops features
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 

Más de aggarwalshoppe14

I need this code, to show ALL inventory items, then with the remove .pdf
I need this code, to show ALL inventory items, then with the remove .pdfI need this code, to show ALL inventory items, then with the remove .pdf
I need this code, to show ALL inventory items, then with the remove .pdf
aggarwalshoppe14
 
I need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdfI need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdf
aggarwalshoppe14
 
I need help creating this flutter applicationPlease provide a com.pdf
I need help creating this flutter applicationPlease provide a com.pdfI need help creating this flutter applicationPlease provide a com.pdf
I need help creating this flutter applicationPlease provide a com.pdf
aggarwalshoppe14
 
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdfHile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
aggarwalshoppe14
 
Hi could I get the java code for all the tasks pls, many thanks!.pdf
Hi could I get the java code for all the tasks pls, many thanks!.pdfHi could I get the java code for all the tasks pls, many thanks!.pdf
Hi could I get the java code for all the tasks pls, many thanks!.pdf
aggarwalshoppe14
 
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdfHere is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
aggarwalshoppe14
 
help write program Project Desoription The purpose of thi project i.pdf
help write program Project Desoription The purpose of thi project i.pdfhelp write program Project Desoription The purpose of thi project i.pdf
help write program Project Desoription The purpose of thi project i.pdf
aggarwalshoppe14
 
I need a case analysis using Harvards Business School format please.pdf
I need a case analysis using Harvards Business School format please.pdfI need a case analysis using Harvards Business School format please.pdf
I need a case analysis using Harvards Business School format please.pdf
aggarwalshoppe14
 

Más de aggarwalshoppe14 (20)

I am sure you have heard the adage �my word is my bond�. We do not k.pdf
I am sure you have heard the adage �my word is my bond�. We do not k.pdfI am sure you have heard the adage �my word is my bond�. We do not k.pdf
I am sure you have heard the adage �my word is my bond�. We do not k.pdf
 
I receive this answer for one of my questions, I need the reference .pdf
I receive this answer for one of my questions, I need the reference .pdfI receive this answer for one of my questions, I need the reference .pdf
I receive this answer for one of my questions, I need the reference .pdf
 
I need this code, to show ALL inventory items, then with the remove .pdf
I need this code, to show ALL inventory items, then with the remove .pdfI need this code, to show ALL inventory items, then with the remove .pdf
I need this code, to show ALL inventory items, then with the remove .pdf
 
I need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdfI need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdf
 
I need help creating this flutter applicationPlease provide a com.pdf
I need help creating this flutter applicationPlease provide a com.pdfI need help creating this flutter applicationPlease provide a com.pdf
I need help creating this flutter applicationPlease provide a com.pdf
 
His Majesty�s Government report that 20 of officials arrive late fo.pdf
His Majesty�s Government report that 20 of officials arrive late fo.pdfHis Majesty�s Government report that 20 of officials arrive late fo.pdf
His Majesty�s Government report that 20 of officials arrive late fo.pdf
 
HIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdf
HIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdfHIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdf
HIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdf
 
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdfHile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
 
Hi, I need help with this Probability question. Please show work and.pdf
Hi, I need help with this Probability question. Please show work and.pdfHi, I need help with this Probability question. Please show work and.pdf
Hi, I need help with this Probability question. Please show work and.pdf
 
Hi could I get the java code for all the tasks pls, many thanks!.pdf
Hi could I get the java code for all the tasks pls, many thanks!.pdfHi could I get the java code for all the tasks pls, many thanks!.pdf
Hi could I get the java code for all the tasks pls, many thanks!.pdf
 
HHI analysis indicates that many states have a highly concentrated i.pdf
HHI analysis indicates that many states have a highly concentrated i.pdfHHI analysis indicates that many states have a highly concentrated i.pdf
HHI analysis indicates that many states have a highly concentrated i.pdf
 
Hello I need help configuring the regression equation for this scatt.pdf
Hello I need help configuring the regression equation for this scatt.pdfHello I need help configuring the regression equation for this scatt.pdf
Hello I need help configuring the regression equation for this scatt.pdf
 
Health Economics with Taxation and Agrarian ReformActivity 2 Grap.pdf
Health Economics with Taxation and Agrarian ReformActivity 2 Grap.pdfHealth Economics with Taxation and Agrarian ReformActivity 2 Grap.pdf
Health Economics with Taxation and Agrarian ReformActivity 2 Grap.pdf
 
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdfHere is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
 
Here is a short amino acid sequence mapped as polar (P) and nonpolar.pdf
Here is a short amino acid sequence mapped as polar (P) and nonpolar.pdfHere is a short amino acid sequence mapped as polar (P) and nonpolar.pdf
Here is a short amino acid sequence mapped as polar (P) and nonpolar.pdf
 
help write program Project Desoription The purpose of thi project i.pdf
help write program Project Desoription The purpose of thi project i.pdfhelp write program Project Desoription The purpose of thi project i.pdf
help write program Project Desoription The purpose of thi project i.pdf
 
I need a case analysis using Harvards Business School format please.pdf
I need a case analysis using Harvards Business School format please.pdfI need a case analysis using Harvards Business School format please.pdf
I need a case analysis using Harvards Business School format please.pdf
 
Household size and educational status are part of ���� Psychologic.pdf
Household size and educational status are part of ���� Psychologic.pdfHousehold size and educational status are part of ���� Psychologic.pdf
Household size and educational status are part of ���� Psychologic.pdf
 
I issued 2000 shares for my society in capsim core how much will be .pdf
I issued 2000 shares for my society in capsim core how much will be .pdfI issued 2000 shares for my society in capsim core how much will be .pdf
I issued 2000 shares for my society in capsim core how much will be .pdf
 
Hay una polilla en Inglaterra llamada polilla moteada. Antes de la r.pdf
Hay una polilla en Inglaterra llamada polilla moteada. Antes de la r.pdfHay una polilla en Inglaterra llamada polilla moteada. Antes de la r.pdf
Hay una polilla en Inglaterra llamada polilla moteada. Antes de la r.pdf
 

Último

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Here are the instructions and then the code in a sec. Please R.pdf

  • 1. Here are the instructions and then the code in a sec. **Please Resubmit the revised and updated Code (GamerService) with Comments added explaining please. RIGHT***** JAVA. HOWEVER IF YOU NEED TO CHANGE THE ENTIRE THING IT IS FINE. I AM DESPERATE. Part II. Java Application: Use the code you submitted in Project One Milestone to continue developing the game application in this project. Be sure to correct errors and incorporate feedback before submitting Project One. Please note: The starter code for this project was provided in the Project One Milestone. If you have not completed the Project One Milestone, you will not be penalized in this assignment, but you will have additional steps to complete to ensure you meet all the components of Project One. Review the class files provided and complete the following tasks to create a functional game application that meets your clients requirements. You will submit the completed game application code for review. Begin by reviewing the base Entity class. It contains the attributes id and name, implying that all entities in the application will have an identifier and name. Software Design Patterns: Review the GameService class. Notice the static variables holding the next identifier to be assigned for game id, team id, and player id. Referring back to Project One Milestone, be sure that you use the singleton pattern to adapt an ordinary class, so only one instance of the GameService class can exist in memory at any given time. This can be accomplished by creating unique identifiers for each instance of a game, team, or player. Your client has requested that the game and team names be unique to allow users to check whether a name is in use when choosing a team name. Referring back to the Project One Milestone, be sure that you use the iterator pattern to complete the addGame() and getGame() methods. Create a base class called Entity. The Entity class must hold the common attributes and behaviors (as shown in the UML diagram provided in the Supporting Materials section below). Refactor the Game class to inherit from this new Entity class. Complete the code for the Player and Team classes. Each class must derive from the Entity class, as demonstrated in the UML diagram. Every team and player must have a unique name by searching for the supplied name prior to adding the new instance. Use the iterator pattern in the addTeam() and addPlayer() methods. Functionality and Best Practices Once you are finished coding, use the main() method provided in the ProgramDriver class to run
  • 2. and test the game application to ensure it is functioning properly. Be sure your code demonstrates industry standard best practices to enhance the readability of your code, including appropriate naming conventions and in-line comments that describe the functionality. Here is my answer that I need a little improvement on its code since I am having trouble making it right. Here I am attaching code for these Files: Entity.java Game.java Team.java Player.java GameService.java ProgramDriver.java SingletonTester.java Source Code for Entity.java package com.gamingroom; public abstract class Entity implements Comparable { private long id; private String name; /* * Constructor with an identifier and name */ public Entity(long id, String name) { this.id = id; this.name = name; } /* * @return id */
  • 3. public long getId() { return id; } /* * @return name */ public String getName() { return name; } @Override public String toString() { return "Entity [id=" + id + ", name=" + name + "]"; } @Override public int compareTo(Entity other) { return Long.compare(this.id, other.id); } } Source Code for Game.Java package com.gamingroom; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Game extends Entity { private static List teams = new ArrayList<>(); /* * Constructor with an identifier and name
  • 4. */ public Game(long id, String name) { super(id, name); } public Team addTeam(String name) { Iterator teamIterator = teams.iterator(); while (teamIterator.hasNext()) { Team team = teamIterator.next(); if (name.equalsIgnoreCase(team.getName())) { return team; } } Team team = new Team(teams.size(), name); teams.add(team); return team; } @Override public String toString() { return "Game [id=" + getId() + ", name=" + getName() + "]"; } } Source Code For Team Java package com.gamingroom; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Team extends Entity {
  • 5. private static List players = new ArrayList<>(); /* * Constructor with an identifier and name */ public Team(long id, String name) { super(id, name); } public Player addPlayer(String name) { Iterator playerIterator = players.iterator(); while (playerIterator.hasNext()) { Player player = playerIterator.next(); if (name.equalsIgnoreCase(player.getName())) { return player; } } Player player = new Player(players.size(), name); players.add(player); return player; } @Override public String toString() { return "Team [id=" + getId() + ", name=" + getName() + "]"; } } Source Code for PLAYER JAVA package com.gamingroom; public class Player extends Entity { /* * Constructor with an identifier and name
  • 6. */ public Player(long id, String name) { super(id, name); } @Override public String toString() { return "Player [id=" + getId() + ", name=" + getName() + "]"; } } Source Code for Game Service package com.gamingroom; import java.util.ArrayList; import java.util.List; /** * A singleton service for the game engine * * @author Bryan Molina****** */ public class GameService { /** * A list of the active games */ private static List games = new ArrayList(); /* * Holds the next game identifier */ private static long nextGameId = 1;
  • 7. private static long nextTeamId = 1; private static long nextPlayerId = 1; // Creating a local instance of this class. Since our constructor is private, // we know that we will only have this one instance of this object making it a singleton. private static GameService instance = new GameService(); // it is normal for a singleton to have a private constructor so that we don't make additional instances outside the class. private GameService() { } //Public accessor for our instance will allow outside classes to access objects in this Singleton Class public static GameService getInstance() { return instance; } //This is the new line for the assignment ** Bryan Molina /** * 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(int i = 0; i < getGameCount(); ++i ) { if (name.equalsIgnoreCase(games.get(i).getName())) { game = games.get(i); } }
  • 8. if (game == null) { game = new Game(nextGameId++, name); games.add(game); } return game; } Game getGame(int index) { return games.get(index); } /** * Returns the game instance with the specified id. * * @param id unique identifier of game to search for * @return requested game instance */ public Game getGame(long id) { // a local game instance Game game = null; // FIXME: Use iterator to look for existing game with same id // if found, simply assign that instance to the local variable for (int i = 0; i < getGameCount(); ++i) { if (games.get(i).getId() == id) { game = games.get(i); } } return game; }
  • 9. /** * Returns the game instance with the specified name. * * @param name unique name of game to search for * @return requested game instance */ public Game getGame(String name) { // a local game instance Game game = null; // FIXME: Use iterator to look for existing game with same name // if found, simply assign that instance to the local variable for(int i = 0; i< getGameCount(); ++i ) { if(name.equalsIgnoreCase(games.get(i).getName())) { game = games.get(i); } } Source Code for Program Driver Java package com.gamingroom; /** * Application start-up program * * @author Bryan Molina *** */ public class ProgramDriver { /** * The one-and-only main() method * * @param args command line arguments */ public static void main(String[] args) {
  • 10. // FIXME: obtain reference to the singleton instance GameService service = GameService.getInstance(); System.out.println("nAbout to test initializing game data..."); // initialize with some game data Game game1 = service.addGame("Game #1"); System.out.println(game1); Game game2 = service.addGame("Game #2"); System.out.println(game2); // use another class to prove there is only one instance SingletonTester tester = new SingletonTester(); tester.testSingleton(); } } return game; } /** * Returns the number of games currently active * * @return the number of games currently active */ public int getGameCount() { return games.size(); } public long getNextPlayerId() { return nextPlayerId++; } public long getNextTeamId() { return nextTeamId++; } }
  • 11. Source Code for SingletonTester JAVA package com.gamingroom; /** * A class to test a singleton's behavior * * @author Bryan Molina ***** */ public class SingletonTester { public void testSingleton() { System.out.println("nAbout to test the singleton..."); // FIXME: obtain local reference to the singleton instance GameService service = GameService.getInstance(); // a simple for loop to print the games for (int i = 0; i < service.getGameCount(); i++) { System.out.println(service.getGame(i)); } } } The expectation I would need is this ProgramDriver (1) [Java Application] CiProgram FilesJavaljdk-19 binljavaw.exe (Mar 18, 2023, 9:32:50 PM - 9:32:52 PM) [pid: 44352] About to test initializing game data... Game [id=1, name=Game #1] Game [ id =2, name = Game #2] About to test the singleton... Game [ id =1, name=Game #1] Game [ id =2, name = Game #2] fun: New Game Service created. About to test initializing game data... Game [id=1, name=Game #1] Game [id=2, name=Game #2] About to test the singleton... Game Service already instantiated. Game [id=1, name=Game #1] Game [id=2, name=Game #2] BUILD