Skip to content

Commit 32fec53

Browse files
committed
Fixed unmerged .gitignore and CalculatorExample2.java
2 parents 599b6c1 + f439ebd commit 32fec53

105 files changed

Lines changed: 1732 additions & 1947 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
*.class
1+
.class
2+
.DS_Store
3+
*/bin
4+
*/.settings
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
55
<classpathentry kind="output" path="bin"/>
66
</classpath>

‎JavaAbstractClassExamples/.settings/org.eclipse.jdt.core.prefs‎

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
package AbstractExample1;
22

3+
// This is the base Animal class.
4+
abstract class Animal {
5+
int age;
6+
String name;
37

4-
// This is the base Animal class.
5-
abstract class Animal {
6-
int age;
7-
String name;
8-
9-
public Animal(String n, int a) {
10-
this.name = n;
11-
this.age = a;
12-
}
13-
14-
public abstract String speak();
15-
16-
public String getName() {
17-
return name;
18-
}
19-
20-
public int getAge() {
21-
return age;
22-
}
8+
public Animal(String n, int a) {
9+
this.name = n;
10+
this.age = a;
2311
}
2412

25-
// A dog is a type of animal.
26-
class Dog extends Animal {
27-
public Dog(String n, int a) {
28-
super(n,a);
29-
}
30-
31-
// We override the speak method so that dog objects return the right sound.
32-
@Override
33-
public String speak() {
34-
return ("Woof!");
35-
}
13+
public abstract String speak();
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public int getAge() {
20+
return age;
21+
}
22+
}
23+
24+
// A dog is a type of animal.
25+
class Dog extends Animal {
26+
public Dog(String n, int a) {
27+
super(n, a);
3628
}
37-
//A cat is a type of animal.
38-
class Cat extends Animal {
39-
public Cat(String n, int a) {
40-
super(n,a);
41-
42-
}
43-
44-
// We override the speak method so that cat objects return the right sound.
45-
@Override
46-
public String speak() {
47-
return ("Meow!");
48-
}
29+
30+
// We override the speak method so that dog objects return the right sound.
31+
@Override
32+
public String speak() {
33+
return ("Woof!");
34+
}
35+
}
36+
37+
// A cat is a type of animal.
38+
class Cat extends Animal {
39+
public Cat(String n, int a) {
40+
super(n, a);
41+
42+
}
43+
44+
// We override the speak method so that cat objects return the right sound.
45+
@Override
46+
public String speak() {
47+
return ("Meow!");
48+
}
49+
}
50+
51+
public class AbstractExampleClass1 {
52+
public static void main(String args[]) {
53+
Dog d = new Dog("Rex", 2);
54+
Cat c = new Cat("Fluffy", 4);
55+
System.out.println(d.speak());
56+
System.out.println(c.speak());
57+
if (d instanceof Animal) {
58+
System.out.println("It's an animal!");
59+
}
60+
if (c instanceof Animal) {
61+
System.out.println("It's an animal!");
4962
}
5063

51-
public class AbstractExampleClass1 {
52-
public static void main(String args[]) {
53-
Dog d = new Dog("Rex",2);
54-
Cat c = new Cat("Fluffy",4);
55-
System.out.println(d.speak());
56-
System.out.println(c.speak());
57-
if (d instanceof Animal) {
58-
System.out.println("It's an animal!");
59-
}
60-
if (c instanceof Animal){
61-
System.out.println("It's an animal!");
62-
}
63-
64-
}
6564
}
65+
}

‎JavaAbstractClassExamples/src/AbstractExample1/package-info.java‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎JavaAbstractClassExamples/src/ArrayExample1/ArrayExampleClass1.java‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,30 @@
33
class TestObj {
44
private int foo;
55
private int bar;
6+
67
public TestObj() {
78
this.foo = 10;
89
this.bar = 20;
910
}
1011
}
12+
1113
public class ArrayExampleClass1 {
1214
public static void main(String args[]) {
13-
int [] ExampleArray1 = {1,2,3,4,5,6,7,8,9,10}; // An array of 10 integers. Already initialized.
14-
int [] ExampleArray2 = new int[10]; // Arrays are objects.
15-
TestObj [] ExampleArray3 = new TestObj[10]; // An array of type TestObj
16-
TestObj t1 = new TestObj();
17-
TestObj t2 = new TestObj();
18-
for (int elem : ExampleArray1) {
19-
System.out.println(elem);
20-
}
21-
22-
// Loading TestObj objects into our array of TestObjs.
23-
ExampleArray3[0]= t1;
24-
ExampleArray3[1]= t2;
25-
15+
// An array of 10 ints already initialized
16+
int[] ExampleArray1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
17+
18+
int[] ExampleArray2 = new int[10]; // Arrays are objects.
19+
20+
TestObj[] ExampleArray3 = new TestObj[10]; // An array of type TestObj
21+
TestObj t1 = new TestObj();
22+
TestObj t2 = new TestObj();
23+
for (int elem : ExampleArray1) {
24+
System.out.println(elem);
25+
}
26+
27+
// Loading TestObj objects into our array of TestObjs.
28+
ExampleArray3[0] = t1;
29+
ExampleArray3[1] = t2;
2630
}
2731
}
2832

‎JavaAbstractClassExamples/src/ArrayExample1/package-info.java‎

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
package InterfaceExample1;
22

3-
43
// We're not using a base class here. We're implementing the speak methods through the Animals interface
54

65
class Dog implements Animals {
7-
6+
87
int age;
98
String name;
10-
11-
public Dog (String n, int a) {
12-
this.age = a;
13-
this.name = name;
9+
10+
public Dog(String n, int a) {
11+
this.age = a;
12+
this.name = name;
1413
}
15-
14+
1615
public String speak() {
1716
return ("Woof!");
1817
}
1918
}
2019

2120
class Cat implements Animals {
22-
21+
2322
int age;
2423
String name;
25-
26-
public Cat (String n, int a) {
27-
this.age = a;
28-
this.name = name;
24+
25+
public Cat(String n, int a) {
26+
this.age = a;
27+
this.name = name;
2928
}
30-
29+
3130
public String speak() {
3231
return ("Meow!");
3332
}
3433
}
3534

3635
public class AnimalInterfaceClassExample1 {
37-
public static void main(String args[]) {
38-
Dog d = new Dog("Rex",2);
39-
Cat c = new Cat ("Fluffy",4);
40-
41-
System.out.println(d.speak());
42-
System.out.println(c.speak());
43-
}
36+
public static void main(String args[]) {
37+
Dog d = new Dog("Rex", 2);
38+
Cat c = new Cat("Fluffy", 4);
39+
40+
System.out.println(d.speak());
41+
System.out.println(c.speak());
42+
}
4443
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package InterfaceExample1;
22

33
public interface Animals {
4-
String speak();
4+
String speak();
55
}

‎JavaAbstractClassExamples/src/InterfaceExample1/package-info.java‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)