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

Consider the following code snippet: PrintWriter outputFile = new Printwriter (f

ID: 3830649 • Letter: C

Question

Consider the following code snippet: PrintWriter outputFile = new Printwriter (filename); write Data (output File); output File.close (); How can the program ensure that the file will be closed if an exception occurs on the writeData call? Explain your answer. A Quiz class contains an array of Question objects. This is best described as an example of... Explain. You are designing a software solution for an automobile rental company. You have decided that the following nouns apply to the requirements: Auto, Customer, Address, Rental Contract, Mileage, Rental Date, Daily Rate, Total. Which of these should be represented as classes? Explain your answer.

Explanation / Answer

8)

We can wrape these statements in try catch finally block and we can close in finally block. Since finally block always execute then it gives the gurantee that it will be closed.

   // opening file
       PrintWriter outputFile = null;
       try {
           outputFile = new PrintWriter(new File(filename));
           writeData(outputFile);
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       }finally{
           if(out != null)
               out.close();
       }

9)

THis is an example of Composition.

Composition is fundamentally different from inheritance. When you use composition, you are (as the other answers note) making a "has-a" relationship between two objects, as opposed to the "is-a" relationship that you make when you use inheritance.

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