用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

设计与实现一个 ISoundable 接口,该接口具有发声功能、还能调节音量大小

2019-07-03 作者: 小居居举报

[java]代码库

package experiment6;

	public interface ISoundable {
		public void increaseVolume();
		public void decreaseVolume();
		public void stopSound();
		public void playSound();
	}

package experiment6;

public class Radio implements ISoundable {
	public void increaseVolume(){
		System.out.println("增大收音机音量");
	}
	public void decreaseVolume(){
		System.out.println("减小收音机音量");
	}
	public void stopSound(){
		System.out.println("关闭收音机");
	}
	public void playSound(){
		System.out.println("收音机播放广播");
	}
}

package experiment6;

public class Mobliephone implements ISoundable{
	public void increaseVolume(){
		System.out.println("增大收音机音量");
	}
	public void decreaseVolume(){
		System.out.println("减小收音机音量");
	}
	public void stopSound(){
		System.out.println("关闭手机");
	}
	public void playSound(){
		System.out.println("手机音乐播放");
	}

}

package experiment6;

public class MusicPeople {
	private String name;
	private int age;
	private void listen(ISoundable s){
		s.playSound();
	}
}

package sunlin;

public class Walkman implements ISoundable{
	public void increaseVolume(){
		System.out.println("增大随身听音量");
	}
	public void decreaseVolume(){
		System.out.println("减小随身听音量");
	}
	public void stopSound(){
		System.out.println("关闭随身听机");
	}
	public void playSound(){
		System.out.println("随身听播放音乐");
	}
}

package sunlin;
import java.util.Scanner;
public class InitailSound {
	public static void main(String[] args){
	int i;
	MusicPeople musicPeople=new MusicPeople();
	Scanner scanner=new Scanner(System.in);
	ISoundable[] soundDevice=new ISoundable[3];
	soundDevice[0]=new Radio();
	soundDevice[1]=new Walkman();
	soundDevice[2]=new Mobliephone();
	System.out.println("你听到什么?请输入选择:0=收音机 1=随身听 2=手机");
	i=scanner.nextInt();
	int n=0;
	while(i>2&&i<=2){
		System.out.println("输入有误:请重新输入");
		i=scanner.nextInt();
		n++;
	}
	if(i<=2){
		musicPeople.listen(soundDevice[i]);
		soundDevice[i].increaseVolume();
		soundDevice[i].stopSound();
		scanner.close();
	}else{
		System.out.println("输入错误,程序已停止");
	}
	}

	private static ISoundable stopSound() {
		// TODO Auto-generated method stub
		return null;
	}

	private static void nextInt() {
		// TODO Auto-generated method stub
		
	}
}

[代码运行效果截图]


设计与实现一个 ISoundable 接口,该接口具有发声功能、还能调节音量大小

[源代码打包下载]




网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...