//Why this is the true "minimum change"
//Only two real changes were required:
//1️⃣ Move the array to class scope
//private Capcom[] newreleases = new Capcom[23];
//2️⃣ Add getter to print title
//public String getTitle()
//Everything else can remain exactly as you wrote it.



public class Gamestore {
		
	public static void main(String[] args)
	{
		/*
		Create an instance of the CreateGamestore class.

		This object (GS) will contain the array that stores
		all Capcom game titles.

		In Java this object is created on the HEAP and the
		reference variable GS is stored on the STACK.
		*/
		CreateGamestore GS = new CreateGamestore();
				
		/*
		These two lines assign Capcom objects into the
		array returned by pctitles().

		pctitles() returns a Capcom[] array.

		So this expression:
		    GS.pctitles()[0]

		means:
		    1. call pctitles()
		    2. obtain the Capcom[] array
		    3. access index 0
		    4. store a Capcom object there
		*/

		GS.pctitles()[0]=new Capcom("Street fighther");
		GS.pctitles()[1]=new Capcom("Capcom vs Marvel");

		//----CHATGPT-----------
		/*
		The following lines demonstrate that the objects
		were successfully stored in the array.

		GS.pctitles()[0]
		    retrieves the Capcom object at index 0.

		.getTitle()
		    calls the getter method to access the private
		    variable 'title'.

		Without the getter method the title could not be
		printed because the variable is private.
		*/
		System.out.println(GS.pctitles()[0].getTitle());
		System.out.println(GS.pctitles()[1].getTitle());
		//----END CHATGPT

	}
}

class Capcom
{
	/*
	This variable stores the title of the game.

	It is declared private so that it cannot be
	directly accessed outside this class.

	This follows the encapsulation principle in OOP.
	*/
	private String title;

	public Capcom(String gamename)
	{
		/*
		This is the constructor.

		It runs automatically whenever a new Capcom
		object is created using:

		    new Capcom("Street fighter")

		The string passed in becomes the title of
		the game object.
		*/
		this.title = gamename;
	}

	//----CHATGPT-----------
	/*
	This is a getter method.

	Purpose:
	    Allows external classes to read the value
	    of the private variable 'title'.

	Without this method, code in main() would not
	be able to access the title.

	This is standard Java encapsulation practice.
	*/
	public String getTitle()
	{
		return title;
	}
	//----END CHATGPT
}

class CreateGamestore
{
	//----CHATGPT-----------
	/*
	IMPORTANT FIX

	In the original code the array was created
	inside the pctitles() method.

	That caused a NEW array to be created every
	time pctitles() was called.

	Example of original behaviour:

	    GS.pctitles()[0] = new Capcom(...)
	    GS.pctitles()[1] = new Capcom(...)

	Execution would effectively become:

	    create array A
	    store element in index 0
	    array A lost

	    create array B
	    store element in index 1
	    array B lost

	So no data persisted.

	SOLUTION:

	Move the array to CLASS LEVEL.

	This means the array is created once when the
	CreateGamestore object is constructed and it
	remains available for the lifetime of the object.
	*/
	private Capcom[] newreleases = new Capcom[23];
	//----END CHATGPT

	public Capcom[] pctitles()
	{
		/*
		ORIGINAL USER CODE (kept for reference)

		Capcom[] newreleases;
		newreleases=new Capcom[23];
		return newreleases;

		This code created a NEW array every time
		the method was called.
		*/

		//----CHATGPT-----------
		/*
		Now this method simply returns the already
		existing array stored in the object.

		So every call to pctitles() refers to the
		same memory location.

		This makes the assignments in main() persistent.
		*/
		return newreleases;
		//----END CHATGPT
	}
}