Day5 Assignments
Day5 Assignments
Objective: Learn how to create and use methods for basic operations in Java.
Instructions:
makefile
Copy
Addition: 5 + 3 = 8
Subtraction: 5 - 3 = 2
Multiplication: 5 * 3 = 15
Division: 5 / 3 = 1.666...
Instructions:
yaml
Copy
Name: John, Age: 20, Marks: 85.5
Name: Alice, Age: 22, Marks: 92.3
Instructions:
yaml
Copy
Employee ID: 101
Employee Name: Mark
Employee Salary: 55000.0
Instructions:
yaml
Copy
Initial balance: 1000.0
Deposited: 500.0
Balance after deposit: 1500.0
Withdrawn: 200.0
Balance after withdrawal: 1300.0
Instructions:
yaml
Copy
Dog says: Bark
Assignment 6: Constructor Overloading (Books and Authors)
Objective: Learn constructor overloading.
Instructions:
yaml
Copy
Book 1: Title: Java Basics, Author: John Doe
Book 2: Title: Advanced Java, Author: Alice Smith, Price: 29.99
Instructions:
Create a base class Shape with a method area() that returns a default area of 0.
Create two subclasses:
Circle with a field radius and an overridden area() method that returns the area of
the circle (π * radius^2).
Rectangle with fields length and width, and an overridden area() method that
returns the area of the rectangle (length * width).
In the main method, create objects of both Circle and Rectangle, and call the
area() method on both using polymorphism.
Example Output:
mathematica
Copy
Area of Circle: 78.54
Area of Rectangle: 20
Instructions:
Create a class SumCalculator with overloaded methods named sum(). The methods
should accept:
Two integers and return their sum.
Three integers and return their sum.
An array of integers and return their sum.
In the main method, call each overloaded sum() method with appropriate arguments.
Example Output:
mathematica
Copy
Sum of 2 numbers: 5 + 3 = 8
Sum of 3 numbers: 5 + 3 + 2 = 10
Sum of array: 1 + 2 + 3 + 4 + 5 = 15