Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
87c9c11
Merge pull request #195 from ResilientSpring/SP7
ResilientSpring Sep 30, 2023
a2bf708
Merge pull request #196 from ResilientSpring/SP7
ResilientSpring Sep 30, 2023
c7aedb8
Merge pull request #197 from ResilientSpring/master
ResilientSpring Oct 1, 2023
1fd5a71
Merge pull request #198 from ResilientSpring/Laptop
ResilientSpring Oct 1, 2023
0adb3fe
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
3dc00bd
Merge branch 'Laptop' of https://github.com/ResilientSpring/Example.g…
ResilientSpring Oct 1, 2023
52fa593
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
54ff00d
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
0a4b2f7
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
c6c5d41
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
edac15b
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
7578b79
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
6cf437d
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
515a00c
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
c58c31c
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
1ca38ce
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
e8d7a68
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
ecfc002
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
d0727c9
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
e19b2e6
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
3eb8547
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
2eeb18c
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
b1c1432
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
7b4d2e1
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
a82c068
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
79aa9f0
Merge pull request #199 from ResilientSpring/Laptop
ResilientSpring Oct 1, 2023
48f9912
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
381bef2
Committed on or around 2023/10/01
ResilientSpring Oct 1, 2023
49e3d93
Merge pull request #200 from ResilientSpring/Laptop
ResilientSpring Oct 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Triangle_2(String s, double w, double h) {
}

Triangle_2(Triangle_2 ob){

super(ob);
}


Expand Down
212 changes: 212 additions & 0 deletions 212 Chapter8/Interface/Implementing_Interfaces.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
package Interface;

//An interface specifies what must be done, but not how to get it done.
interface Series4{

int getNext();
void reset();
void setStart(int x);
}


//Implement Series.
class ByTwos2_ implements Series4{

// It's both permissible and common for classes that implement interfaces to define additional members
// of their own. (It absolutely is. Without it, how to implement methods in an interface?)
int start;
int value;

public ByTwos2_() {
start = 0;
value = 0;
}

// Whenever you implement a method defined by an interface, it must be implemented as public;
// because all members of an interface are implicitly public.
public int getNext() {
value += 2;
return value;
}

public void reset() {
value = start;
}

@Override
public void setStart(int x) {

start = x;
value = x;

}
}


class ByTwos4 implements Series4{
int start;
int value;
int previous;

public ByTwos4() {
start = 0;
value = 0;
}

ByTwos4(int previous) {

this.previous = previous;

start = 0;
value = 0;
}

// Whenever you implement a method defined by an interface, it must be implemented as public;
// because all members of an interface are implicitly public.
public int getNext() {
value += 2;
return value;
}

public void reset() {
value = start;
}

@Override
public void setStart(int x) {

start = x;
value = x;

}

// Even though the interface does not define this method, it's both permissible and common for classes
// that implement interfaces to define additional members of their own.
int getPrevious() {
return previous;
}
}


class ByThrees2 implements Series4{ // implement Series in a different way.
int start;
int value;

ByThrees2() {
// TODO Auto-generated constructor stub
start = 0;
value = 0;
}

public int getNext() {
value += 3;
return value;
}

public void reset() {
value = start;
}

public void setStart(int x) {
start = x;
value = x;
}
}


// If a class includes an interface but does not fully implement the methods defined by that interface, then
// that class must be declared as abstract.
abstract class implicate implements Series4{

int start;

public void setStart(int start) {
this.start = start;
}

}


public class Implementing_Interfaces {

public static void main(String[] args) {
// TODO Auto-generated method stub

ByTwos2_ oByTwos2_ = new ByTwos2_();

for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + oByTwos2_.getNext());
}

System.out.println("\nResetting");

oByTwos2_.reset();

for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + oByTwos2_.getNext());
}

System.out.println("\nStarting at 100");

oByTwos2_.setStart(100);

for (int i = 0; i < 5; i++) {

System.out.println("Next value is " + oByTwos2_.getNext());
}

System.out.println();

ByTwos4 oByTwos4 = new ByTwos4(9);

for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + oByTwos4.getNext());
}

System.out.println("\nResetting");

oByTwos4.reset();

for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + oByTwos4.getNext());
}

System.out.println("\nStarting at 100");

oByTwos4.setStart(100);

for (int i = 0; i < 5; i++) {

System.out.println("Next value is " + oByTwos4.getNext());
}

System.out.println();

ByThrees2 oByThrees2 = new ByThrees2();

for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + oByThrees2.getNext());
}

System.out.println("\nResetting");

oByThrees2.reset();

for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + oByThrees2.getNext());
}

System.out.println("\nStarting at 100");

oByThrees2.setStart(100);

for (int i = 0; i < 5; i++) {

System.out.println("Next value is " + oByThrees2.getNext());
}

System.out.println();

}

}
71 changes: 71 additions & 0 deletions 71 Chapter8/Interface/Series_Demo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package Interface;

// An interface specifies what must be done, but not how to do it.
interface Series2{

int getNext();
void reset();
void setStart(int x);
}


// Implement Series.
class ByTwos2 implements Series2{
int start;
int value;

public ByTwos2() {
start = 0;
value = 0;
}

// Whenever you implement a method defined by an interface, it must be implemented as public;
// because all members of an interface are implicitly public.
public int getNext() {
value += 2;
return value;
}

public void reset() {
value = start;
}

@Override
public void setStart(int x) {

start = x;
value = x;

}
}

public class Series_Demo {

public static void main(String[] args) {

ByTwos2 oByTwos2 = new ByTwos2();

for (int i = 0; i < 5; i++) {

System.out.println("Next value is " + oByTwos2.getNext());
}

System.out.println("\nResetting");

oByTwos2.reset();

for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + oByTwos2.getNext());
}

System.out.println("\nStarting at 100");

oByTwos2.setStart(100);

for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + oByTwos2.getNext());
}

}

}
86 changes: 86 additions & 0 deletions 86 Chapter8/Interface/Series_Demo2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package Interface;

//An interface specifies what must be done, but not how to do it.
interface Series3{

int getNext();
void reset();
void setStart(int x);
}


//Implement Series.
class ByTwos3 implements Series3{
int start;
int value;
int previous;

public ByTwos3() {
start = 0;
value = 0;
}

ByTwos3(int previous) {

this.previous = previous;

start = 0;
value = 0;
}

// Whenever you implement a method defined by an interface, it must be implemented as public;
// because all members of an interface are implicitly public.
public int getNext() {
value += 2;
return value;
}

public void reset() {
value = start;
}

@Override
public void setStart(int x) {

start = x;
value = x;

}

int getPrevious() {
return previous;
}
}

public class Series_Demo2 {

public static void main(String[] args) {
// TODO Auto-generated method stub

ByTwos3 obByTwos3 = new ByTwos3(9);


for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + obByTwos3.getNext());
}

System.out.println("\nResetting");

obByTwos3.reset();

for (int i = 0; i < 5; i++) {
System.out.println("Next value is " + obByTwos3.getNext());
}

System.out.println("\nStarting at 100");

obByTwos3.setStart(100);

for (int i = 0; i < 5; i++) {

System.out.println("Next value is " + obByTwos3.getNext());
}

}

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.