CoreJava - ClassesObjectsMethods - Assignment
CoreJava - ClassesObjectsMethods - Assignment
Classes, Objects, Methods:
- 1. Create a class called "Person" with instance variables for name, age, and gender.
- 2. Create an object of the "Person" class and set its instance variables.
- 3. Write a method in the "Person" class that prints out the person's name, age, and gender.
- 4. Write a method that calculates the age of a person based on their birth year.
- 5. Write a method that checks if a person is an adult (over 18 years old).
- 6. Create a class called "Rectangle" with instance variables for length and width.
- 7. Write a method in the "Rectangle" class that calculates the area of the rectangle.
- 8. Write a method that calculates the perimeter of a rectangle.
- 9. Create a class called "Student" with instance variables for name, grade, and GPA.
- 0 Write a method that prints out a student's name, grade, and GPA.
- 11. Write a method that takes two integers as parameters and returns their sum.
- 12. Write a method that takes a string as a parameter and returns the length of the string.
- 13. Write a method that takes an array of integers as a parameter and returns the sum of the array.
- 14. Write a static method that calculates the factorial of a number.
- 15. Write a non-static method that calculates the area of a circle.
- 16. Write a method that takes two integers as parameters and returns the larger of the two.
- 17. Write a method that takes two integers as parameters and returns their product.
- 18. Write a method that takes a string as a parameter and returns the string in reverse.
- 19. Write a method that takes an array of integers as a parameter and returns the average of the array.
- 20. Write a parameterized constructor for the "Rectangle" class that takes length and width as parameters and sets the instance variables.
Pass By Value & Pass by Reference:
- 21. Write a method that takes an integer as a parameter and increments it by 1.
- 22. Write a method that takes an array of integers as a parameter and sets all values to 0.
- 23. Write a method that takes an object of the "Person" class as a parameter and sets their age to 0.
- 24. Write a method that takes a string as a parameter and appends "hello" to the string.
- 25. Write a method that takes an array of strings as a parameter and sorts the array in alphabetical order.
Recursive Methods:
- 26. Write a method that calculates the factorial of a number recursively.
- 27. Write a method that calculates the Fibonacci sequence recursively.
- 28. Write a method that prints out the numbers from 1 to n recursively.
- 29. Write a method that calculates the sum of the digits of a number recursively.
- 30. Write a method that checks if a string is a palindrome recursively.
Constructors:
- 31. Write a default constructor for the "Person" class that sets the instance variables to default values.
- 32. Write a parameterized constructor for the "Person" class that takes name, age, and gender as parameters and sets the instance variables.
- 33. Write a non-parameterized constructor for the "Rectangle" class that sets the length and width to 0.
- 34. Write a parameterized constructor for the "Rectangle" class that takes length and width as parameters and sets the instance variables.
- 35. Write a constructor for the "Student" class that sets the instance variables to default values.
Variables:
- 36. Create a static variable called "count" in the "Person" class that counts the number of persons created.
- 37. Create an instance variable called "grade" in the "Student" class that represents the student's grade level.
- 38. Create a local variable called "sum" in a method that calculates the sum of two integers.
- 39. Create an instance variable called "balance" in a bank account class.
- 40. Create a static variable called "PI" in a math class that represents the value of pi.
Access Modifiers/Specifiers:
- 41. Create a public method in a class that prints out a message.
- 42. Create a private instance variable in a class that represents the class's password.
- 43. Create a protected method in a class that returns the class's name.
- 44. Create a default instance variable in a class that represents the class's size.
- 45. Create a public static variable in a class that represents the class's ID.
Operators:
- 46. Write a program that uses the relational operators to compare two integers.
- 47. Write a program that uses the assignment operator to assign a value to a variable.
- 48. Write a program that uses the arithmetic operators to calculate the sum, difference, product, and quotient of two integers.
- 49. Write a program that uses the logical operators to determine if a number is positive and even.
- 50. Write a program that uses the unary operators to increment and decrement a variable.
Conditional Statements and Loops:
- 51. Write a program that uses an if statement to determine if a number is positive or negative.
- 52. Write a program that uses an if-else statement to determine if a number is even or odd.
- 53. Write a program that uses a switch statement to determine the day of the week.
- 54. Write a program that uses a for loop to print out the numbers from 1 to 10.
- 55. Write a program that uses a while loop to calculate the factorial of a number.
- 56. Write a program that uses a do-while loop to ask the user for their name and prints out a greeting.
- 57. Write a program that uses a for-each loop to print out the elements of an array.
- 58. Write a program that uses a break statement to exit a loop.
- 59. Write a program that uses a continue statement to skip an iteration of a loop.
- 60. Write a program that uses nested loops to print out a multiplication table.
Inheritance:
- 61. Create a class called "Animal" with instance variables for name and age.
- 62. Create a subclass of "Animal" called "Dog" with instance variables for breed and weight.
- 63. Create a method in the "Animal" class called "makeSound".
- 64. Override the "makeSound" method in the "Dog" class to make a barking sound.
- 65. Create a constructor in the "Animal" class that takes arguments for name and age.
Comments
Post a Comment