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

Points distribution: Lab Report Questions 20% (Template is in Doc Sharing) Comme

ID: 3537408 • Letter: P

Question

Points distribution:

Lab Report Questions 20% (Template is in Doc Sharing)

Comments 20%

No Syntax (Complier) error 20%

No Runtime (system) error 20%

No Logical Error (correct results) 20%

11.1, Object-oriented programming allows you to derive new classes from existing classes. This is called inheritance. Inheritance is an important and powerful feature in Java for reusing software. Suppose you are to define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design these classes so to avoid redundancy and make the system easy to comprehend and easy to maintain? The answer is to use inheritance.

why inheritance?

13.1, Runtime errors occur while a program is running if the environment detects an operation that is impossible to carry out. For example, if you access an array using an index out of bounds, your program will get a runtime error with an ArrayIndexOutOfBoundsException. To read data from a file, you need to create a Scanner object using new Scanner(new File(filename)) (see Listing 9.6). If the file does not exist, your program will get a runtime error with a FileNotFoundException.

14.9 Processing Primitive Data Type Values as Objects

Owing to performance considerations, primitive data types are not used as objects in Java. Because of the overhead of processing objects, the language%u2019s performance would be adversely affected if primitive data types were treated as objects. However, many Java methods require the use of objects as arguments. For example, the add(object) method in the ArrayList class adds an object to an ArrayList. Java offers a convenient way to incorporate, or wrap, a primitive data type into an object (e.g., wrapping int into the Integer class, and wrapping double into the Double class). The corresponding class is called a wrapper class. By using a wrapper object iwhy wrapper class?

Java provides Boolean, Character, Double, Float, Byte, Short, Integer, and Long wrapper classes for primitive data types. These classes are grouped in the java.lang package. Their inheritance hierarchy is shown in Figure 14.8.

nstead of a primitive data type variable, you can take advantage of generic programming.

------------------------------------------------------------------------------------------------------------------

Figure 15.17 The FontMetrics class can be used to determine the font properties of characters for a given font.


FontMetrics is an abstract class. To get a FontMetrics object for a specific font, use the following getFontMetrics methods defined in the Graphics class:

You can use the following instance methods in the FontMetrics class to obtain the attributes of a font and the width of a string when it is drawn using the font:

public int getAscent() // Return the ascent

public int getDescent() // Return the descent

public int getLeading() // Return the leading

public int getHeight() // Return the height

public int stringWidth(String str) // Return the width of the string

Listing 15.6 gives an example that displays a message in the center of the panel, as shown in Figure 15.18.

--------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

Figure 19.13 The program copies a file.


To copy the contents from a source to a target file, it is appropriate to use a binary input stream to read bytes from the source file and a binary output stream to send bytes to the target file, regardless of the contents of the file. The source file and the target file are specified from the command line. Create an InputFileStream for the source file and an OutputFileStream for the target file. Use the read() method to read a byte from the input stream, and then use the write(b) method to write the byte to the output stream. Use BufferedInputStream and BufferedOutputStream to improve the performance. Listing 19.4 gives the solution to the problem.

--------------------------------------------------------------------------------------------------------------------

Explanation / Answer

11.1 Inheritance is used in these cases because it saves space by accessing already defined data members and functions.

13.1 question is not asked in this part.

14.9 Wrapper class is used because it wraps a data type into objects that can be used to access data members and functions.


_________________________________________


**Questions are not assked in other parts also....


I have answered all questions asked above.


plz rate....