1. Replace void with String in class' methods
2. Classes implement interfaces 3. Add interface use demo
This commit is contained in:
3
Callable.java
Normal file
3
Callable.java
Normal file
@@ -0,0 +1,3 @@
|
||||
public interface Callable{
|
||||
void call();
|
||||
}
|
||||
3
Emailable.java
Normal file
3
Emailable.java
Normal file
@@ -0,0 +1,3 @@
|
||||
public interface Emailable{
|
||||
void SendEmail(String text);
|
||||
}
|
||||
22
Main.java
22
Main.java
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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("Совершён звонок!");
|
||||
}
|
||||
}
|
||||
@@ -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("Письмо отправлено!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user