Java user class, interface to realize mobile phone functions -- practice the use of interface

Posted by divedj on Wed, 23 Oct 2019 17:46:18 +0200

|--Requirement description

 

|--Realization ideas

1. According to the inheritance logic, it is determined that all mobile phones have a mobile phone parent class, which is defined as an abstract class, in which two abstract methods are defined to realize calling and sending information.

2. According to the logic of.... has....a.. Interface, it is determined that four types are needed --- camera interface, mobile network interface, audio playback interface and video playback interface.

3. Create Sony and HTC mobile phone classes respectively, inherit mobile phone classes, and access interfaces according to requirements.

 

|--Code content

 1 /**
 2  * @auther:: 9527
 3  * @Description: Define the function of the mobile phone itself. This class is the parent class of later mobile phones.
 4  * @program: oop
 5  * @create: 2019-07-16 22:54
 6  */
 7 public abstract class Phones {
 8     //Phone
 9     public abstract void call();  
10     //Send message
11     public abstract void text();
12     //Mobile phone model
13     public abstract void type();
14 }
Parent class -- Phones
 1 /**
 2  * @auther:: 9527
 3  * @Description: Mobile network
 4  * @program: oop
 5  * @create: 2019-07-16 23:08
 6  */
 7 public interface Mobil {
 8     //network
 9     void wangLuo();
10 }
Interface mobile network
 1 /**
 2  * @auther:: 9527
 3  * @Description: Realize photo taking function
 4  * @program: oop
 5  * @create: 2019-07-16 23:01
 6  */
 7 public interface Camera {
 8     //Photograph
 9     void camera();
10 }
Interface camera
 1 /**
 2  * @auther:: 9527
 3  * @Description: Play audio
 4  * @program: oop
 5  * @create: 2019-07-16 22:59
 6  */
 7 public interface PlayMp3 {
 8     //Play audio
 9     void playMp3();
10 }
Interface audio
 1 /**
 2  * @auther:: 9527
 3  * @Description: Play video
 4  * @program: oop
 5  * @create: 2019-07-16 22:57
 6  */
 7 public interface PlayMp4 {
 8     //Play video
 9     void playMp4();
10 }
Interface -- play video
 1 /**
 2  * @auther:: 9527
 3  * @Description: HTC Mobile phone
 4  * @program: oop
 5  * @create: 2019-07-16 23:02
 6  */
 7 public class HTCI1900 extends Phones implements PlayMp4,PlayMp3,Camera,Mobil{
 8 
 9 
10     @Override
11     public void type() {
12         System.out.println("This is a part. HTC Of I9100 Mobile phone");
13     }
14 
15     @Override
16     public void camera() {
17         System.out.println("Click, take a picture successfully");
18     }
19 
20     @Override
21     public void call() {
22         System.out.println("Start a video call");
23     }
24 
25     @Override
26     public void text() {
27         System.out.println("Send text with picture");
28     }
29 
30     @Override
31     public void playMp3() {
32         System.out.println("Play "today is a good day"");
33     }
34 
35     @Override
36     public void playMp4() {
37         System.out.println("Start to play "little time"");
38     }
39 
40     @Override
41     public void wangLuo() {
42         System.out.println("Access to mobile network");
43     }
44 }
Mobile phone -- Sony
 1 /**
 2  * @auther:: 9527
 3  * @Description: G520C Mobile phone
 4  * @program: oop
 5  * @create: 2019-07-16 22:56
 6  */
 7 public class PhoneG520C extends Phones implements PlayMp3 {
 8     @Override
 9     public void call() {
10         System.out.println("Start voice call");
11     }
12 
13     @Override
14     public void text() {
15         System.out.println("Send text message");
16     }
17 
18     @Override
19     public void type() {
20         System.out.println("This is a model for G502C Sony Mobile");
21     }
22 
23     @Override
24     public void playMp3() {
25         System.out.println("Start playing the music cool");
26     }
27 }
Mobile phone --HTC
 1 /**
 2  * @auther:: 9527
 3  * @Description: Test class
 4  * @program: oop
 5  * @create: 2019-07-16 23:10
 6  */
 7 public class PhoneMgr {
 8     public static void main(String[] args) {
 9         //Realize Sony Mobile
10         PhoneG520C suoni = new PhoneG520C();
11         suoni.type();
12         suoni.playMp3();
13         suoni.text();
14         suoni.call();
15 
16         System.out.println("\n");
17 
18         //Realization HTC Mobile phone
19         HTCI1900 htc = new HTCI1900();
20         htc.type();
21         htc.wangLuo();
22         htc.playMp4();
23         htc.camera();
24         htc.text();
25         htc.call();
26     }
27 
28 }
Test class -- implementation of mobile phone

 

|--Operation results

 

| -- process error

nothing

Topics: PHP Mobile network