I will post The following below
1. Assignment 2 Rubric requirements
2. Design notes.
3. Assignment 1 of another student
read the following an perform as mentioned . and comment on every changes that were made ..
Design notes of Ali
1. How do you think you would add file reading and writing functionality to your menu program,
Answer:
We should create two methods for reading and writing respective. Each method will call based
on the what user select on the menu.
When program show the menu for user select one of them, list of option should included the
option for reading file and writing file.
In each method, the program should ask the user for name file need to read or need to write.
When user select the option reading file, after asked them for name file, the program will create a
file with this name and then check if it existed or not. If this file not existed, the program will
show the message error for user and then ask they select again. If the file existed, the program
will open file and reading file. Also, show the content of file.
For the option writing file, the program will do the same for ask file name and check if it existed
or not then show error if not existed. If the file existed, the program open the file and ready
writing. The program ask user for text need be write to file.
After reading writing finish, the program need close the file.
2. Describe how you think the try-catch feature of Java work and what exactly the
FileNotFoundException class is,
Answer:
The try-catch is used to enclose the code that might throw an exception and handle the Exception. It
must be used within the method. If exception is handled by the application programmer, normal flow
of the application is maintained i.e. rest of the code is executed. Each catch block is an exception
handler that handles the type of exception indicated by its argument. The argument type,
ExceptionType, declares the type of exception that the handler can handle and must be the name of
a class that inherits from the Throwable class. The handler can refer to the exception with name.
The catch block contains code that is executed if and when the exception handler is invoked. The
runtime system invokes the exception handler when the handler is the first one in the call stack whose
ExceptionType matches the type of the exception thrown. The system considers it a match if the
thrown object can legally be assigned to the exception handler’s argument.
Exception handlers can do more than just print error messages or halt the program. They can do error
recovery, prompt the user to make a decision, or propagate the error up to a higher-level handler using
chained exceptions.
The FileNotFoundException class is handle for code block do open a file failed. The file with the
specified pathname does not exist. It will also be thrown by these constructors if the file does exist but
for some reason is inaccessible, for example when an attempt is made to open a read-only file for
writing.
3. Identify sections of your code that you could create automated reusable methods out of,
Answer:
Sections of code could create automated reusable method out of is:
–
–
Show the menu:
System.out.println(“\nMenu: “);
System.out.println(“1 – Name of the file”);
System.out.println(“2 – Text to write in to file”);
System.out.println(“3 – Number”);
System.out.println(“Q – Quit”);
System.out.print(“Select: “);
Generate list of number in range [1-100]
int[] total = new int[10];
//init value
for(int i = 0; i < 10; i++)
total[i] = 0;
//generate 1000 random number in range 1 - 100
System.out.println("Generating 1000 random numbers in range 1 - 100");
Random rand = new Random();
int i = 0;
while(i < 1000)
{
int randomNum = rand.nextInt((100 - 1) + 1) + 1;
if(randomNum