Exercise 1: Basic If-Else Statement Sum of 5, 10, and 15: 30
Problem:
Write a program that prompts the user to enter a
number and then checks if the number is Exercise 1: Basic If-Else Statement
positive, negative, or zero. Print a message Problem:
indicating the type of number. Write a program that prompts the user to enter a
Sample Output: number and then checks if the number is
Input: 5 → Output: The number is positive. positive, negative, or zero. Print a message
Input: -3 → Output: The number is indicating the type of number.
negative. Sample Output:
Input: 0 → Output: The number is zero. Input: 5 → Output: The number is positive.
Exercise 2: Looping - Sum of Even Numbers Input: -3 → Output: The number is
Problem: negative.
Write a program that uses a for loop to calculate Input: 0 → Output: The number is zero.
and print the sum of all even numbers between 1 Exercise 2: Looping - Sum of Even Numbers
and 100. Problem:
Expected Output: Write a program that uses a for loop to calculate
The sum of even numbers from 1 to 100 and print the sum of all even numbers between 1
is 2550. and 100.
Expected Output:
Exercise 3: Basic Class and Object Creation The sum of even numbers from 1 to 100
(OOP) is 2550.
Problem:
Create a class named Car with the following Exercise 3: Basic Class and Object Creation
properties and methods: (OOP)
Properties: String brand, String model, int Problem:
year Create a class named Car with the following
Method: displayInfo() - displays the details properties and methods:
of the car in the format: "Brand: [brand], Properties: String brand, String model, int
Model: [model], Year: [year]". year
Write a main method to create an object of Method: displayInfo() - displays the details
the Car class, assign values to its properties, and of the car in the format: "Brand: [brand],
call displayInfo() to print the car's details. Model: [model], Year: [year]".
Sample Output: Write a main method to create an object of
yaml the Car class, assign values to its properties, and
Copy code call displayInfo() to print the car's details.
Sample Output:
Brand: Toyota, Model: Corolla, Year: 2020 yaml
Exercise 4: While Loop - Multiplication Table Copy code
Problem:
Write a program that prompts the user to enter a Brand: Toyota, Model: Corolla, Year: 2020
number and then prints the multiplication table Exercise 4: While Loop - Multiplication Table
for that number up to 10 using a while loop. Problem:
Sample Output for Input 5: Write a program that prompts the user to enter a
5x1=5 number and then prints the multiplication table
5 x 2 = 10 for that number up to 10 using a while loop.
... Sample Output for Input 5:
5 x 10 = 50 5x1=5
Exercise 5: Method Overloading (OOP) 5 x 2 = 10
Problem: ...
Create a class called Calculator with two methods 5 x 10 = 50
named add: Exercise 5: Method Overloading (OOP)
The first add method takes two integer Problem:
parameters and returns their sum. Create a class called Calculator with two methods
The second add method takes three named add:
integer parameters and returns their sum. The first add method takes two integer
In the main method, create an instance of parameters and returns their sum.
the Calculator class, call both add methods, and The second add method takes three
print the results. integer parameters and returns their sum.
Sample Output:
Sum of 5 and 10: 15
In the main method, create an instance of
the Calculator class, call both add methods, and
print the results.
Sample Output:
Sum of 5 and 10: 15
Sum of 5, 10, and 15: 30