Programming Asignment
Programming Asignment
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.// Person.java
2.Public class Person {
3. Private String name;
4.Private int age;
5.Public Person (String name, int age) {
6.this.name = name;
7.this.age = age;
8.}
9.Public String getName() {
10.Return name;
11.}
12.Public int getAge() {
13.return 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.// Dog.java
2.Public class Dog {
6.this.name = name;
7.this.breed = breed;
8.}
11. }
14. }
17. }
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.//Rectangle.java
2.public class Rectangle {
3. private double width;
4. private double height;
1. //Circle.java
2. public class Circle {
3.private double radius;
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.//Employee.java
2.Public class Employee {
3. Private String name;
4. Private String jobTitle;
5.Private double salary;
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.//Rectangle.java
2.public class Rectangle extends Shape {
3.private double length;
4. private double width;