GAMBELLA UNIVERSTY
FACULTY OF NATURAL AND COMPUTAIONAL SCIENCE
DEPARTMENT OF COMPUTER SCIENCE
COURCE TITLE:OOP
Summitted by:
Name Id
Fitsum 5302
teshome
Birhan fentie 7774
Temesgen 6588
dereje
Fikade tilaye 5607
Tizazu 6402
sitotawu
Summitted to:Eyoas
Summistion date:10/4/2016
Ethiopian -Gambella
1. Write a Java program to create a class called "Person" with a name and age
attribute. Create two instances of the "Person" class, set their attributes using the
constructor, and print their name and age.
1.// [Link]
[Link] class Person {
3. Private String name;
[Link] int age;
[Link] Person (String name, int age) {
[Link] = name;
[Link] = age;
8.}
[Link] String getName() {
[Link] name;
11.}
[Link] int getAge() {
[Link] age;
14.}
15. }
2. Write a Java program to create a class called "Dog" with a name and breed
attribute. Create two instances of the "Dog" class, set their attributes using the
constructor and modify the attributes using the setter methods and print the
updated values.
1.// [Link]
[Link] class Dog {
[Link] String name;
4. Private String breed;
[Link] Dog(String name, String breed) {
[Link] = name;
[Link] = breed;
8.}
9. Public String getName() {
10. return name;
11. }
12. public void setName(String name) {
13. [Link] = name;
14. }
15. public String getBreed() {
16. return breed;
17. }
18. public void setBreed(String breed) {
19. [Link] = breed;
20. }
21.}
3. Write a Java program to create a class called "Rectangle" with width and
height attributes. Calculate the area and perimeter of the rectangle.
1.//[Link]
[Link] class Rectangle {
3. private double width;
4. private double height;
5. public Rectangle(double width, double height) {
6. [Link] = width;
7. [Link] = height;
8. }
9. public double getWidth() {
10. return width;
11. }
12. public void setWidth(double width) {
13. [Link] = width;
14. }
15. Public double getHeight() {
16. return height;
17. }
18. public void setHeight(double height) {
19. [Link] = height;
20. }
21. public double getArea() {
22. return width * height;
23. }
24. public double getPerimeter() {
25. return 2 * (width + height);
26. }
27.}
4. Write a Java program to create a class called "Circle" with a radius attribute.
You can access and modify this attribute. Calculate the area and circumference
of the circle.
1. //[Link]
2. public class Circle {
[Link] double radius;
4. public Circle(double radius) {
5. [Link] = radius;
6. }
7. Public double getradius() {
8. return radius;
9. }
10. public void setRadius(double radius) {
11. [Link] = radius;
12. }
13. public double getArea() {
14. return [Link] * radius * radius;
15. }
16. public double getCircumference() {
17. return 2 * [Link] * radius;
18. }
19.}
5. Write a Java program to create a class called "Employee" with a name, job
title, and salary attributes, and methods to calculate and update salary.
1.//[Link]
[Link] class Employee {
3. Private String name;
4. Private String jobTitle;
[Link] double salary;
6. public Employee(String name, String jobTitle, double salary)
{
7. [Link] = name;
8. [Link] = jobTitle;
9. [Link] = salary;
10. }
11. public String getName() {
12. return name;
13. }
14. public void setName(String name) {
15. [Link] = name;
16. }
17. public String getJobTitle() {
18. return jobTitle;
19. }
20. public void setJobTitle(String jobTitle) {
21. [Link] = jobTitle;
22. }
23. public double getSalary() {
24. return salary;
25. }
[Link] void setSalary(double salary) {
27. [Link] = salary;
28. }
29. public void raiseSalary(double percentage) {
30. salary = salary + salary * percentage / 100;
31. }
32. public void printEmployeeDetails() {
33. [Link]("Name: " + name);
34. [Link]("Job Title: " + jobTitle);
35. [Link]("Salary: " + salary);
36. }
37.}
6. Write a Java program to create a class called "Shape" with abstract methods
for calculating area and perimeter, and subclasses for "Rectangle", "Circle", and
"Triangle".
1.//[Link]
[Link] class Rectangle extends Shape {
[Link] double length;
4. private double width;
5. public Rectangle(double length, double width) {
6. [Link] = length;
7. [Link] = width;
8. }
[Link] double getArea() {
10. return length * width;
11. }
12. Public double getPerimeter() {
13. return 2 * (length + width);
14. }
15.}