Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b2a0c15

Browse files
Update README.md
1 parent c9b85af commit b2a0c15

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

‎README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This repository contains a collection of Java programming exercises, structured
66
- [Level 1 Tasks](#level-1-tasks)
77
- [Level 2 Tasks](#level-2-tasks)
88
- [Level 3 Tasks](#level-3-tasks)
9+
- [Level 4 Tasks](#level-4-tasks)
910
- [Mini Projects](#mini-projects)
1011

1112
## Level 1 Tasks
@@ -394,6 +395,133 @@ Combine all features from the previous exercises into a single Bank application.
394395
Expected Output:
395396
A fully functional bank application with user interactions, account creation, deposits, withdrawals, and validation.
396397

398+
## Level 4 Tasks
399+
Exercise 1: Constructor Overloading
400+
• Task: Create a class Book with two constructors: one that initializes only the title and another that initializes both the title and the author. Implement a method to display the book details.
401+
• Output:
402+
Book Title: The Great Gatsby
403+
Author: Unknown
404+
Book Title: 1984
405+
Author: George Orwell
406+
________________________________________
407+
Exercise 2: Constructor Chaining
408+
• Task: Implement a class Person with a constructor that initializes the name. Use constructor chaining to create another constructor that initializes both name and age. Display the person’s details.
409+
• Output:
410+
Name: Alice
411+
Age: 0
412+
Name: Bob
413+
Age: 25
414+
________________________________________
415+
Exercise 3: Method Overriding
416+
• Task: Create a base class Shape with a method area(). Derive classes Circle and Rectangle from Shape and override the area() method to return the area of the respective shape. Demonstrate polymorphism using an array of Shape references.
417+
• Output:
418+
Circle Area: 78.5
419+
Rectangle Area: 30.0
420+
________________________________________
421+
Exercise 4: Reference vs Object
422+
• Task: Create a class Car with a model property. Instantiate a Car object and use a reference variable to access and display the car's model.
423+
• Output:
424+
Car Model: Tesla Model 3
425+
________________________________________
426+
Exercise 5: Method Overloading
427+
• Task: Implement a class Calculator with overloaded methods for add(). Create methods to add two integers, three integers, and two doubles. Display the results of each method call.
428+
• Output:
429+
Sum of 3 and 5: 8
430+
Sum of 3, 4, and 5: 12
431+
Sum of 2.5 and 3.5: 6.0
432+
________________________________________
433+
Exercise 6: Inheritance and Super Keyword
434+
• Task: Create a class Employee with properties like name and salary. Derive a class Manager from Employee and add an additional property department. Use the super keyword to initialize inherited properties. Display the details of a manager.
435+
• Output:
436+
Name: John Doe
437+
Salary: 60000
438+
Department: Sales
439+
________________________________________
440+
Exercise 7: Abstract Classes
441+
• Task: Create an abstract class Appliance with an abstract method turnOn(). Derive classes WashingMachine and Refrigerator from Appliance and implement the turnOn() method. Demonstrate the functionality.
442+
• Output:
443+
Washing Machine is now ON.
444+
Refrigerator is now ON.
445+
________________________________________
446+
Exercise 8: Interface Implementation
447+
• Task: Define an interface Playable with a method play(). Create classes Song and Video that implement this interface. Call the play() method for each.
448+
• Output:
449+
Playing song: Shape of You
450+
Playing video: Tutorial
451+
________________________________________
452+
Exercise 9: Exception Handling
453+
• Task: Create a method divide(int a, int b) that throws an ArithmeticException when dividing by zero. Implement a try-catch block to handle this exception and display an appropriate message.
454+
• Output:
455+
Cannot divide by zero.
456+
________________________________________
457+
Exercise 10: Static Members
458+
• Task: Implement a class Counter with a static variable count that increments every time an object is created. Create multiple Counter objects and display the total count.
459+
• Output:
460+
Total Count of Objects: 5
461+
________________________________________
462+
463+
Exercise 11: Exploring Polymorphism with Method Overriding
464+
465+
Task: Create a base class named Shape with a method draw(). Then, create two subclasses, Circle and Square, each overriding the draw() method to display a specific message for the shape. Demonstrate polymorphism by creating a Shape reference that can point to objects of both Circle and Square.
466+
Expected Output:
467+
When calling the draw() method on the Shape reference, it should output the specific messages for both shapes.
468+
469+
________________________________________
470+
Exercise 12: Library Management System
471+
Task: Create a simple Library Management System that allows users to add books, view the list of available books, and check out books. Use classes to represent Books and the Library.
472+
Requirements:
473+
1. Book Class:
474+
o Attributes:
475+
 title (String)
476+
 author (String)
477+
 isCheckedOut (boolean)
478+
o Methods:
479+
 Constructor to initialize the attributes.
480+
 toString() method to return a string representation of the book (title and author).
481+
 Use Method Overloading: Create multiple toString() methods that provide different levels of detail (e.g., one for just the title and another for title and author).
482+
2. Library Class:
483+
o Attributes:
484+
 books (ArrayList of Book)
485+
o Methods:
486+
 addBook(Book book): Adds a book to the library.
487+
 Use Constructor Overloading: Provide a constructor that allows initializing the Library with a list of books.
488+
 viewBooks(): Displays all books in the library. Indicate if a book is checked out or available.
489+
 Use Polymorphism: If you decide to create different types of books (e.g., EBook, AudioBook), this method can utilize polymorphism to display their details based on their specific classes.
490+
 checkOutBook(String title): Allows a user to check out a book by title. If the book is not available, display an appropriate message.
491+
3. Main Class:
492+
o Create an instance of the Library.
493+
o Add at least 5 books to the library using the addBook method.
494+
o Display the list of books using the viewBooks method.
495+
o Implement a simple menu that allows users to check out a book by entering the book title.
496+
Output:
497+
The program should interactively allow users to perform the following actions:
498+
• Display the list of books with their availability.
499+
• Check out a book by title, updating its status.
500+
• Display an appropriate message if the book is already checked out.
501+
Example Output:
502+
Available Books:
503+
1. The Great Gatsby by F. Scott Fitzgerald (Available)
504+
2. 1984 by George Orwell (Available)
505+
3. To Kill a Mockingbird by Harper Lee (Available)
506+
4. The Catcher in the Rye by J.D. Salinger (Available)
507+
5. Moby Dick by Herman Melville (Available)
508+
509+
Enter the title of the book you want to check out: 1984
510+
You have checked out "1984" by George Orwell.
511+
512+
Available Books:
513+
1. The Great Gatsby by F. Scott Fitzgerald (Available)
514+
2. 1984 by George Orwell (Checked Out)
515+
3. To Kill a Mockingbird by Harper Lee (Available)
516+
4. The Catcher in the Rye by J.D. Salinger (Available)
517+
5. Moby Dick by Herman Melville (Available)
518+
Suggested Features and Their Usage:
519+
• Polymorphism: If you extend the Book class to create different types of books (like EBook or AudioBook), use polymorphism in the viewBooks method to call overridden methods from these subclasses, allowing for specific implementations of how each type of book is displayed.
520+
• Method Overloading: In the Book class, overload the toString() method to provide different string representations, enhancing the readability and usability of your class.
521+
• Constructor Overloading: Use constructor overloading in the Library class to allow for different ways of creating a library instance, such as initializing it with an empty list of books or with a predefined list.
522+
523+
524+
397525
## Mini Projects
398526

399527
### Mini-Project 1: ATM Simulation Program

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /