Question: Section 1 : Classes and Objects ( 1 5 points ) 1 . 1 Define a class named ` Rectangle ` with attributes ` length

Section 1: Classes and Objects (15 points)
1.1 Define a class named `Rectangle` with attributes `length` and `width`. Include a method named calculate Area that returns the area of the rectangle.
1.2 Create an object of the Rectangle class in the main method, set its length and width, and display the calculated area.
1.3 Explain the concept of encapsulation and how it is implemented in Java.
Section 2: Inheritance and Polymorphism (20 points)
2.1 Create a base class `Vehicle` with attributes `brand` and `year`. Include a method start Engine that prints "Engine started."
2.2 Derive a subclass Car from Vehicle with an additional attribute `NumDoors`. Override the startEngine method to print "Car engine started."
2.3 In the main method, create objects of both Vehicle and Car classes. Demonstrate polymorphism by calling the startEngine method on both objects.
Section 3: Exceptions (15 points)
3.1 Write a Java program that divides two numbers. Handle the ArithmeticException to display a custom error message if division by zero occurs.
3.2 Explain the purpose of the try,catch, and finally blocks in exception handling.
3.3 Write a code snippet demonstrating the use of the throws keyword in a method declaration.
Section 4: Swing GUI (20 points)
4.1 Create a simple Swing GUI application with a JFrame containing a JButton. When the button is clicked, display a JOptionPane with a message.
4.2 Explain the role of the Event Dispatch Thread (EDT) in Swing applications and why it's important.
4.3 Implement a JTextField and a JLabel in your Swing application. Update the label text dynamically based on the input in the text field.
Section 5: Comprehensive Program (10 points)
Write a Java program that incorporates the concepts of classes, objects, inheritance, polymorphism, exceptions, and Swing GUI. The program should include at least one custom exception, a class hierarchy, and a graphical user interface.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!