Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4bbf2c2

Browse files
committed
'some changes'
2 parents 2aa8748 + 72e0564 commit 4bbf2c2

File tree

6 files changed

+249
-3
lines changed

6 files changed

+249
-3
lines changed

src/Animal.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
public class Animal {
2+
String name;
3+
float weight;
4+
String size;
5+
6+
//a constructor is an especial method that execute at the beginning when object of class is created.
7+
8+
//no parameterized
9+
Animal() {
10+
11+
}
12+
13+
//parameterized
14+
Animal(String name, float weight, String size) {
15+
this.name = name;
16+
this.weight = weight;
17+
this.size = size;
18+
}
19+
20+
Animal(String name, float weight) {
21+
this.name = name;
22+
this.weight = weight;
23+
24+
}
25+
26+
Animal(String name) {
27+
this.name = name;
28+
29+
}
30+
31+
Animal(String size, String name) {
32+
this.size = size;
33+
this.name = name;
34+
35+
}
36+
37+
//copy constructor
38+
Animal(Animal animal) {
39+
this.name = animal.name;
40+
this.weight = animal.weight;
41+
this.size = animal.size;
42+
}
43+
44+
}
45+

src/Bird.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
public class Bird {
2+
String colour;
3+
String family;
4+
float length;
5+
6+
// Constructor with 'family' parameter
7+
Bird(String family){
8+
this.family=family;
9+
}
10+
11+
//important: why can't I make constructor that assign colour properties of the bird?
12+
13+
// Constructor with 'colour' and 'family' parameters
14+
Bird(String colour, String family, float length){
15+
this.colour=colour;
16+
this.family=family;
17+
this.length=length;
18+
}
19+
20+
// Constructor with 'colour' and 'length' parameters
21+
Bird(String colour, float length){
22+
this.colour=colour;
23+
this.length=length;
24+
}
25+
26+
// Constructor with 'length' and 'family' parameters
27+
Bird(float length, String family){
28+
this.length=length;
29+
this.family=family;
30+
}
31+
32+
// Constructor with 'length' parameter
33+
Bird(float length){
34+
this.length=length;
35+
}
36+
}

src/Furniture.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Furniture {
2+
String name;
3+
int breadth;
4+
5+
Furniture(String name, int breadth){
6+
this.name=name;
7+
this.breadth=breadth;
8+
}
9+
10+
}
11+
//why we make constructor: to make the object.
12+
//syntax of object Wall s1= new House();
13+
//public class House{}
14+
// this is constructor House(){}

src/House.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
public class House {
2+
//this is data declaration while creating class
3+
String name;
4+
int bedrooms;
5+
int toilets;
6+
7+
8+
//parametrized constructor
9+
House(String name, int bedrooms, int toilets) {
10+
this.name = name;
11+
this.bedrooms = bedrooms;
12+
this.toilets = toilets;
13+
14+
}
15+
void findingArea(){
16+
System.out.println("This is the finding area functions.");
17+
}
18+
19+
void cookingFood(){
20+
System.out.println("This is the cooking food functions");
21+
}
22+
void cleaningBathroom(){
23+
System.out.println("This is the cleaning bathroom functions");
24+
}
25+
void changingBedsheet(){
26+
System.out.println("This is the changing bedsheet functions.");
27+
}
28+
void HooveringHouse(){
29+
System.out.println("This is the hoovering house functions");
30+
}
31+
32+
33+
//no parameter constructor
34+
House() {
35+
36+
}
37+
38+
House(String name) {
39+
this.name = name;
40+
}
41+
42+
House(String name, int bedrooms) {
43+
this.name = name;
44+
this.bedrooms = bedrooms;
45+
}
46+
47+
House(int bedrooms, String name) {
48+
this.bedrooms = bedrooms;
49+
this.name = name;
50+
}
51+
52+
House(int toilets, int bedrooms, String name) {
53+
this.toilets = toilets;
54+
this.bedrooms = bedrooms;
55+
this.name = name;
56+
57+
}
58+
59+
House(int bedrooms, int toilets) {
60+
this.bedrooms = bedrooms;
61+
this.toilets = toilets;
62+
}
63+
//copy constructor
64+
//h1 is the data type of House that's why it expect the data type house as we have created h1 in main folder
65+
House(House h1){
66+
this.name=h1.name;
67+
this.toilets=h1.toilets;
68+
this.bedrooms=h1.bedrooms;
69+
}
70+
71+
}
72+

src/Main.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ class Shape {
1313
}
1414

1515

16-
Shape(double area){
17-
this.area=area;
18-
}
1916

17+
Shape(double area) {
18+
this.area = area;
19+
}
2020

2121
Shape(Shape s1) {
2222
this.colour = s1.colour;
@@ -36,8 +36,55 @@ public static void main(String[] args) {
3636
System.out.println("properties of s2");
3737
System.out.println(s2.colour);
3838
System.out.println(s2.area);
39+
40+
Animal a1 = new Animal("dog", 46, "medium");
41+
42+
System.out.println(a1.name);
43+
44+
45+
Animal a2 = new Animal();
46+
System.out.println("please enter your animal name");
47+
a2.name = "cat";
48+
a2.weight = 23;
49+
a2.size = "small";
50+
51+
Animal a3 = new Animal(a2);
52+
System.out.println(a3.weight);
53+
54+
Bird b1 = new Bird("parrot", "huge", 26);
55+
System.out.println(b1.colour);
56+
System.out.println(b1.family);
57+
System.out.println(b1.length);
58+
59+
Furniture f1 = new Furniture("Bed", 18);
60+
System.out.println(f1.name);
61+
System.out.println(f1.breadth);
62+
63+
System.out.println("This is h1 house");
64+
House h1 = new House("Aakritiko House", 4, 2);
65+
System.out.println(h1.name);
66+
System.out.println(h1.bedrooms);
67+
System.out.println(h1.toilets);
68+
h1.changingBedsheet();
69+
h1.cleaningBathroom();
70+
71+
System.out.println("This is h2 house");
72+
House h2 = new House(h1);
73+
System.out.println(h2.name);
74+
System.out.println(h2.bedrooms);
75+
System.out.println(h2.toilets);
76+
System.out.println("This is h3 house");
77+
House h3 = new House(h2);
78+
System.out.println(h3.name);
79+
System.out.println(h3.toilets);
80+
System.out.println(h3.bedrooms);
81+
82+
83+
Vehicle v1= new Vehicle("car",12600, "fifteen years old","four seats");
84+
System.out.println(v1.name);
3985
}
4086
}
87+
4188
//primitives data types
4289
//int, double, String, float, long , short, byte, boolean
4390
//wrapper classes

src/Vehicle.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public class Vehicle {
2+
String name;
3+
int price;
4+
String modelOfVehicle;
5+
String noOfSeats;
6+
7+
Vehicle(String name, int price, String modelOfVehicle, String noOfSeats){
8+
this.name=name;
9+
this.price=price;
10+
this.modelOfVehicle=modelOfVehicle;
11+
this.noOfSeats=noOfSeats;
12+
}
13+
Vehicle(String name){
14+
this.name=name;
15+
}
16+
Vehicle(String modelOfVehicle, int price){
17+
this.modelOfVehicle=modelOfVehicle;
18+
this.price=price;
19+
}
20+
Vehicle(String modelOfVehicle, String noOfSeats){
21+
this.modelOfVehicle=modelOfVehicle;
22+
this.noOfSeats=noOfSeats;
23+
}
24+
Vehicle(String noOfSeats, int price, String name){
25+
this.noOfSeats=noOfSeats;
26+
this.price=price;
27+
this.name=name;
28+
}
29+
30+
31+
32+
}

0 commit comments

Comments
 (0)