1) Create a method called: public void loadMemory(String fileName) Create the ne
ID: 3530009 • Letter: 1
Question
1) Create a method called:
public void loadMemory(String fileName)
Create the necessary instructions for this method to open a file whose name is given as a parameter and copy its contents into the memory array instance variable. Think about how you will handle the exceptions that will be thrown when you use the Java I/O API. You should handle all exceptions within your new loadMemory(String) method. How will you know when there is no more data to read?
Remember: the program.ex file is a binary file, not a text file. Note: Be sure to use getMessage() and printStackTrace() in your exception handling.
2)In "Computer"class, implement a new run method via overloading which takes the name of the executable file as a parameter. This method will provide the same functionality as your original run method except that it will load a program from a file instead of just loading a default program.
Explanation / Answer
This creates a potential mutable hole in an otherwise immutable data type. For example, the following implementation of aVectoris mutable.
public class Complex { private final double re; private final double im; public Complex(double real, double imag) { re = real; im = imag; } // compile-time error public void plus(Complex b) { re = this.re + b.re; // oops, overwrites invoking object's value im = this.im + b.re; // compile-time error since re and im are final return new Complex(re, im); } } Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.