Job (s) 6

A job, the mobile phone interface

The original phone, you can send text messages, telephone. With the development, the phone adds features: Audio, video player, camera, Internet. Use the phone interface functions;

First create the parent class phone:Copy the code

package com.phone.jiekou;

public abstract class HandSet {
    private String brand;
    private String type;
    
    public HandSet() {}
    
    public HandSet(String brand,String type) {
        this.brand = brand;
        this.type = type;        
        
    }
    
    public String getBrand() {
        return brand;
    }
    public void setBrand(String brand) {
        this.brand = brand;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public abstract void message();
    public abstract void call();
Copy the code

Create a phone function interface:

1, Internet access interfaces:

package com.phone.jiekou;

public interface Network {
    public void net();

}

2, camera interfaces:

package com.phone.jiekou;

public interface Photo {
    public void takePhoto();
}

3, play video function interface:

package com.phone.jiekou;

public interface Play {
    public void play(String film);

}

4, play audio function interface:

package com.phone.jiekou;

public interface Music {
    public void boFang(String music);

}

Create a common mobile phone such requests have playback of audio features:

Copy the code
com.phone.jiekou Package; 

public class CommonPhone the extends the implements Music HandSet { 
    
    public CommonPhone () { 
        
    } 
    
    public CommonPhone (Brand String, String type) { 
        Super (Brand, type); 
        
    } 

    public void the showInfo () { 
        System.out.println ( "mobile information and features:"); 
        System.out.println ( "this is a" + this.getBrand () + "phone, the model is" + this.getType ()); 
    } 
    public void the message ( ) { 
        System.out.println ( "send SMS!"); 
    } 

    
    public void call () { 
        System.out.println ( "call!"); 
    } 


    
    public void boFang (String Music) { 
        System.out.println ( "play" + music + "!");
    }}

Copy the code

Create a smart phone class required to have Internet access, camera, video playback function

Copy the code
com.phone.jiekou Package; 

public class the implements the Network HandSet the extends the SmartPhone, Photo, Play { 
    
    public the SmartPhone () {} 
    public the SmartPhone (Brand String, String type) { 
        Super (Brand, type); 
    } 
    

    public void the showInfo () { 
        the System .out.println ( "phone information and features:"); 
        System.out.println ( "this is a" + this.getBrand () + "phone, the model is" + this.getType ()); 
    } 
    
    play void public (String film) { 
        System.out.println ( "Movies" + film); 
    } 

    
    public void takePhoto () { 
        System.out.println ( "camera"); 
    } 

    
    public void NET () { 
        System. out.println ( "Internet access");
    }

    
    Message void public () { 
        System.out.println ( "Send SMS"); 
    } 

    
    public void Call () { 
        System.out.println ( "call"); 
    } 

}
Copy the code

Write test classes:

Copy the code
package com.phone.jiekou;

public class TestPhone {
    public static void main(String[] args) {
        CommonPhone cphone = new CommonPhone("三星","I3452");
        cphone.showInfo();
        cphone.message();
        cphone.call();
        cphone.boFang("音乐");
        
        SmartPhone sphone = new SmartPhone("苹果","6P");
        sphone.showInfo();
        sphone.message();
        sphone.call();
        sphone.play("大话西游");
        sphone.net();
        sphone.takePhoto();
        
        
    }

}
Copy the code

Achieve results:

Copy the code
Phone information and Features: 
This is a Samsung phone model I3452 is 
sending text messages! 
dial number! 
You can play music! 
Phone information and Features: 
This is an Apple phone, the model is 6P 
send text messages 
to make calls 
to play movies Odyssey 
Internet-enabled 
camera

Guess you like

Origin www.cnblogs.com/zdxzdx/p/11319579.html