Question
Purpose : This week we will practice more basics of Object Oriented Programming. This will also give you the opportunity to see how well you
Purpose:
This week we will practice more basics of Object Oriented Programming. This will also give you the opportunity to see how well you wrote the previous week's code. (See this: https://www.chegg.com/homework-help/questions-and-answers/purpose-tasked-design-npc-class-used-create-npc-objects-upcoming-video-game-npc-stands-non-q56263744) If you find that you have to redo a lot of your old code from last week's assignment so this week's code can work, then that means you did not plan last week's assignment with extensibility in mind. Always be thinking about how code you write today can be extended and updated in the future.
Detailed Instructions: Package Declaration and General Setup:
- Create a new project in Eclipse for this assignment.
- Create a package in your new project called hw04.
- Copy and paste your .java files from Homework 03 into the package in your new project.
- NOTE: You will need to make sure that all features from last week's assignment are complete before you can begin this week's assignment.
- Do not forget to include the header comment, as well as comments throughout your code documenting your work.
The Npc Class Additions:
Data Fields:
- numberOfNPCs: Add a static data field to your NPC class which will be an integer. This data field will only have a getter, no setter. This data field shall increase by 1 every time a new NPC object is created. Remember that all static data is shared among all instances of your class. All classes should have the same value for this data field if you implement it correct. HINT: Only change this value in the constructors.
Methods:
- getDialogue(): Update this getter to return a deep copy of the dialogue array. Changes to the returned copy SHOULD NOT affect the array stored in the dialogue data field.
- toString(): Update your toString() method to show the current value of numberOfNPCs. Add this information right before the printout of the dialogue. Follow the same general formatting as the toString() output example from the previous assignment.
The NpcMain Class Additions:
- NPC Array:
- Store all of your NPC objects inside of an array of type NPC.
- HINT: For the initial 3 NPC objects, have a method which creates these objects, places them into an array, and then returns a reference to the array containing these objects. This will be the storage array that you will use for the rest of the testing.
- Create a static method in your NpcMain class called resizeNpcArray:
- This method shall accept an array of NPC objects as input.
- The purpose of this method is the expand our NPC array by one, making room for a new NPC object to be added.
- This method shall create a new empty array of NPC objects that is +1 size of the original NPC array that is passed to the method.
- This method shall copy the data from the input array to the new array.
- If the input array has 4 NPC objects at indexes 0 ~ 3, then the new empty array will have a size of 5 and the 4 existing objects will be copied to indexes 0 ~ 3 of the new array, with index 4 of the new array remaining empty to make room for adding a new NPC object.
- You must use the System.arraycopy(src, src_index, dest, dest_index, length) method to copy the data from the original array to the new array.
- This method shall return the new array now populated with the NPC objects previously created, and with an empty space at the end to add a new NPC object.
- Creating Custom NPCs:
- Write a static method called createNewNPC() that takes no parameters.
- This method shall allow the user to create a new NPC object and return the new NPC object from the method.
- The createNewNPC() method should request the following information:
- NPC name
- Race
- xPos and yPos
- If the NPC will have sequential or random dialogue
- Next will be to ask the user for the dialogue for the NPC. Ask the user how many lines of dialogue they will be entering. Use this value as the size of the dialogue array. Now have the user enter the dialogue one line at a time, until they have entered all the lines of dialogue.
- BIG HINT: Recall what happens when you mix any of the Scanner methods with the nextLine() method and how to fix this. If you don't remember this behavior, you may find that your program will skip over requesting certain information. Think this through very carefully.
- Once all of the information has been gathered, create a new NPC object, return it from this method, and store it in the array of NPC objects.
- HINT: You will need to make sure your resize method is fully functional and that it can correctly create space in a new array of NPC objects to make room to add the object created by the createNewNPC() method.
- Dynamically Updating Menu 1
- Now that the user has the ability to create custom NPC objects, you will need to dynamically generate the text and options for Menu 1.
- Hopefully you already thought about this and have implemented code in your Homework 03 to accommodate this change.
- Example if there are 4 NPC objects, then the first 4 options of Menu 1 should be the names of the 4 NPCs. The last two options will always be to create a new NPC and to exit the program. Example menu text below:
- Choose an NPC
- 1.
- 2.
- 3.
- 4.
- 5. Create new NPC.
- 6. Exit Program
Enter the number choice (1-6):
-
-
- Example if there are 7 NPC objects, then the first 7 options of Menu 1 should be the names of the 7 NPCs. The last two options will always be to create a new NPC and to exit the program.
-
-
-
- Choose an NPC
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8. Create new NPC.
- 9. Exit Program
-
Enter the number choice (1-9):
-
- HINT: Properly breaking your NPCMain file into smaller, more manageable methods will go a VERY long way to helping you implement the NPC creation feature. A good rule of thumb is this: if you cannot succinctly describe what your method is doing in one or two sentences, it probably can be broken down into smaller methods. Also, I really like this person's post on StackOverflow (Links to an external site.) about method length. Give it a read please, you may find it very informative.
Submission of Deliverables:
- You will need to turn in all .java files related to this assignment.
- Please zip your src folder from your Eclipse project and turn in the entire .zip file to Canvas by the due date and time.
- As long as you zip the src folder, your file structure will be preserved, and I will be able to more easily grade your assignment.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started