1. Replace void with String in class' methods

2. Classes implement interfaces
3. Add interface use demo
This commit is contained in:
2025-09-26 17:34:40 +07:00
parent d0c8f6a35b
commit a3ebe491e4
5 changed files with 39 additions and 20 deletions

3
Callable.java Normal file
View File

@@ -0,0 +1,3 @@
public interface Callable{
void call();
}

3
Emailable.java Normal file
View File

@@ -0,0 +1,3 @@
public interface Emailable{
void SendEmail(String text);
}

View File

@@ -20,10 +20,20 @@ public class Main{
ArrayList<PersonalContact> pc = new ArrayList<PersonalContact>();
ArrayList<WorkContact> wc = new ArrayList<WorkContact>();
Callable if1 = new PersonalContact();
Callable if2 = new WorkContact();
Emailable if3 = new WorkContact();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in, System.console().charset()));
char ch = 0;
{
if1.call();
if2.call();
if3.SendEmail("Example email");
}
while(true){
MenuPrint();
@@ -222,13 +232,13 @@ public class Main{
for(PersonalContact x : pc){
if(x.name.equals(name)){
x.getInfo();
System.out.println(x.getInfo());
break;
}
}
for(WorkContact x : wc){
if(x.name.equals(name)){
x.getInfo();
System.out.println(x.getInfo());
break;
}
}
@@ -236,22 +246,22 @@ public class Main{
}
case('5'):{ // Show all contacts
for(PersonalContact x : pc){
x.getInfo();
System.out.println(x.getInfo());
}
for(WorkContact x : wc){
x.getInfo();
System.out.println(x.getInfo());
}
break;
}
case('6'):{ // Show all work contacts
for(WorkContact x : wc){
x.getInfo();
System.out.println(x.getInfo());
}
break;
}
case('7'):{ // Show all personal contacts
for(PersonalContact x : pc){
x.getInfo();
System.out.println(x.getInfo());
}
break;
}

View File

@@ -1,13 +1,13 @@
public class PersonalContact extends GenericContact{
public class PersonalContact extends GenericContact implements Callable{
String birthdate;
String commentary;
String address;
void getInfo(){
System.out.println("\nВся известная информация о " + this.name + ":");
System.out.println(this.number);
System.out.println(this.birthdate);
System.out.println(this.commentary);
System.out.println(this.address);
String getInfo(){
return this.name + " " + this.number + " " + this.birthdate + " " + this.commentary + " " + this.address;
}
public void call(){
System.out.println("Совершён звонок!");
}
}

View File

@@ -1,13 +1,16 @@
public class WorkContact extends GenericContact{
public class WorkContact extends GenericContact implements Callable, Emailable{
String company;
String duty;
String email;
void getInfo(){
System.out.println("\nВся известная информация о " + this.name + ":");
System.out.println(this.number);
System.out.println(this.company);
System.out.println(this.duty);
System.out.println(this.email);
String getInfo(){
return this.name + " " + this.number + " " + this.company + " " + this.duty + " " + this.email;
}
public void call(){
System.out.println("Совершён звонок!");
}
public void SendEmail(String msg){
System.out.println("Письмо отправлено!");
}
}