public class Cupcake extends Generics {
	// Class data
	public static KeyTypes key = KeyType.title;  // static initializer
	public static void setOrder(KeyTypes key) {Cupcake.key = key;}
	public enum KeyType implements KeyTypes {title, flavor, frosting, sprinkles}

	// Instance data
	private final String frosting;
	private final int sprinkles;
	private final String flavor;

	// Constructor
	Cupcake(String frosting, int sprinkles, String flavor)
	{
		this.setType("Cupcake");
		this.frosting = frosting;
		this.sprinkles = sprinkles;
		this.flavor = flavor;
	}

	/* 'Generics' requires getKey to help enforce KeyTypes usage */
	@Override
	protected KeyTypes getKey() { return Cupcake.key; }

	/* 'Generics' requires toString override
	 * toString provides data based off of Static Key setting
	 */
	@Override
	public String toString() {		
		String output="";
		if (KeyType.flavor.equals(this.getKey())) {
			output += this.flavor;
		} else if (KeyType.frosting.equals(this.getKey())) {
			output += this.frosting;
		} else if (KeyType.sprinkles.equals(this.getKey())) {
			output += "00" + this.sprinkles;
			output = output.substring(output.length() - 2);
		} else {
			output = super.getType() + ": " + this.flavor + ", " + this.frosting + ", " + this.sprinkles;
		}
		return output;
	}

	// Test data initializer
	public static Cupcake[] cupcakes() {
		return new Cupcake[]{
            new Cupcake("Red", 4, "Red Velvet"),
			    new Cupcake("Orange", 5, "Orange"),
			    new Cupcake("Yellow", 6, "Lemon"),
			    new Cupcake("Green", 7, "Apple"),
			    new Cupcake("Blue", 8, "Blueberry"),
			    new Cupcake("Purple", 9, "Blackberry"),
			    new Cupcake("Pink", 10, "Strawberry"),
			    new Cupcake("Tan", 11, "Vanilla"),
			    new Cupcake("Brown", 12, "Chocolate"),
		};
	}
	
	public static void main(String[] args)
	{
		// Inheritance Hierarchy
		Cupcake[] objs = cupcakes();

		// print with title
		Cupcake.setOrder(KeyType.title);
		Cupcake.print(objs);

		// print flavor only
		Cupcake.setOrder(KeyType.flavor);
		Cupcake.print(objs);
	}
	
}
Cupcake.main(null);
|   public class Cupcake extends Generics {
cannot find symbol
  symbol:   class Generics

|   	public static KeyTypes key = KeyType.title;  // static initializer
cannot find symbol
  symbol:   class KeyTypes

|   	public static void setOrder(KeyTypes key) {Cupcake.key = key;}
cannot find symbol
  symbol:   class KeyTypes

|   	protected KeyTypes getKey() { return Cupcake.key; }
cannot find symbol
  symbol:   class KeyTypes

|   	public enum KeyType implements KeyTypes {title, flavor, frosting, sprinkles}
cannot find symbol
  symbol:   class KeyTypes

|   		this.setType("Cupcake");
cannot find symbol
  symbol: method setType(java.lang.String)

|   	@Override
method does not override or implement a method from a supertype

|   	@Override
method does not override or implement a method from a supertype

|   			output = super.getType() + ": " + this.flavor + ", " + this.frosting + ", " + this.sprinkles;
non-static variable super cannot be referenced from a static context

|   			output = super.getType() + ": " + this.flavor + ", " + this.frosting + ", " + this.sprinkles;
cannot find symbol
  symbol: method getType()

|   		Cupcake.print(objs);
cannot find symbol
  symbol:   method print(Cupcake[])

|   		Cupcake.print(objs);
cannot find symbol
  symbol:   method print(Cupcake[])
FRQ 2017 #3- Methods and Control Structures
(a)

This frq is trying to go over how to use specific methods and alter them in order to change a substring

the method replaceNthOccurrence is asked to be written to change the nth occurrence of a substring with a replacement string, str with repl
Methods:
A method in Java is a block of code that, when called, performs specific actions mentioned in it. You can insert values or parameters into methods, and they will only be executed when called. A method is similar to a function.

Control Structures:
Control Structures can be considered as the building blocks of computer programs. A program is usually not limited to a linear sequence of instructions since during its process it may bifurcate, repeat code or bypass sections.
//Part (a)
public void replaceNthOccurrence(String str, int n, String repl)
{

int loc = findNthOccurrence(str, n);

if (loc != -1)
{
currentPhrase = currentPhrase.substring(0, loc) + repl + currentPhrase.substring(loc + str.length());
}
}
public void replaceNthOccurrence(String str, int n, String repl){
    int i = findNthOccurrence(str, n);
    if(i != -1)
    {
        String a = currentPhrase.substring(0, i); 
        //find the string from first index up till i

        String b = currentPhrase.substring(i+str.length());
        //everything after the str

        currentPhrase = a + repl + b;

    }
}