Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, can anybody help me what to put on these methods? I need some hints and help

ID: 3527398 • Letter: H

Question

Hi, can anybody help me what to put on these methods? I need some hints and help, how do you call a method? I am very lost. /** * The run method should perform the loadMemory() operation and begin * cycling through the fetch, increment, execute cycle by calling the * cycle() method. */ void run(); /** * The cycle method should first create a boolean variable to use * in determining the stop condition. Using a while loop, you can then * loop on the fetch() increment() and execute() methods. Note that * the execute method returns a boolean, this is how you determine * if the loop should terminate. */ void cycle(); /** * The fetch method retrieves the value stored in memory at the location * given by the program counter, and stores this value in the instruction * register. */ void fetch(); /** * The increment method increments the value of the program counter. * THINK: you already have a method that does this. */ void increment(); /** * The execute method converts the opcode stored in the instruction * register to the code that corresponds to this instruction number. * See the above defined final static ints for further explanation * of each instruction. If you remember switch statements from * last semester, one might come in handy now. * * Note that we return a boolean from this method. This boolean is * used in our cycle method to determine when to end the loop. * When do we end the loop? When the STOP instruction is thrown of * course! * @return boolean endLoopCondition */ boolean execute();

Explanation / Answer

First off, lets make sure that we know what a method is. A method is the same as a function, or just something that can be done, but is normally used more than once. When you call a method in Java, that function is being used. For instance, look at this method: "public static void methodExample() {}". It currently has no code in it, but there are three keywords before the method name. There is public, static, and void.

The word public before the method name means that the method itself can be called from anywhere else. That includes other classes, even from different packages (files) as long as you import the class. There are three other words that can replace public. They are protected and private. If a method is protected, then only this class and subclasses (classes that use this as a basis to build off of) can call the method. If a method is private, then the method can only be called inside the class. The last keyword is really not even a word. This is if you had nothing in the place of public, protected, or private. This is called the default, or package-private. This means that only the classes in the same package can call the method.
3
The second keyword, static means that the method is not a function of an object, but a function of the class. Since it is a function of the class, then the method must be called using the class name first: "ExampleClass.methodExample()". However, if the keyword static was not there, then the method would be a function of an object created from that class. For instance, if the class was called ExampleObject and it had a constructor (for making objects), then we could make a new object by typing ExampleObject obj, and call the method with "obj.methodExample()". Without the keyword static, the method must be called like that.
4
The last word before the method name is void. The word void means that when the method is called, the method will run whatever code is inside it, but it won't return anything (give something back when you run the method). If you do want a method to return something, then simply replace the word void with the object of your choosing that you want the method to give. Then just add return plus an object of that type somewhere toward the end of the method's code.
5
When calling a method that returns something, you can use what it returns. For example, if a someMethod returns an integer, then you can set an integer to what it returns with "int a = someMethod()"
6
Some methods require a parameter. A method that requires a parameter of an integer would look like someMethod(int a) When using a method like this, you would write the method name, and then an integer in the parentheses: someMethod(5) or someMethod(n) if n is an integer.
7
Methods can also have multiple parameters, simply separated by commas. If the method someMethod required two parameters, int a and Object obj, it would look like "someMethod(int a, Object obj)". To use this new method, it would be called by the method name followed by an integer and an Object in parentheses: someMethod(4, thing) where thing is an Object.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote