package rg;
import java.util.Scanner;
interface Soundable {
public abstract void playSound();
public abstract void lower();
public abstract void stop();
}
class Phone implements Soundable{
@Override
public void playSound() {
System.out.println("手机出声了,快接");
}
@Override
public void lower() {
System.out.println("手机调音量了");
}
@Override
public void stop() {
System.out.println("手机关机了");
}
}
class Radio implements Soundable{
@Override
public void playSound() {
System.out.println("收音机出声了,");
}
@Override
public void lower() {
System.out.println("收音机调音量了");
}
@Override
public void stop() {
System.out.println("收音机关机了");
}
}
class Walkman implements Soundable{
@Override
public void playSound() {
System.out.println("随身听出声了");
}
@Override
public void lower() {
System.out.println("随身听调音量了");
}
@Override
public void stop() {
System.out.println("随身听关机了");
}
}
class Usersound {
public void use(Soundable s) {
s.playSound();
System.out.println("是否降低音量? 1、是 2、否");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
if (a == 1) {
s.lower();
System.out.println("是否要关机?1、是 2、否");
int b = sc.nextInt();
if (b == 1) {
s.stop();
}
}
}
}
public class secondwork {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请选择你要进行的设备:1、手机。2、收音机。3、随身听");
int x=sc.nextInt();
Usersound u=new Usersound();
if (x==2){
u.use(new Radio());
}else if (x==3){
u.use(new Walkman());
}else if (x==1){
u.use(new Phone());
}else{
System.out.println("输入的有误");
}
}
}
标签:void,System,aaaa,Override,println,public,out
From: https://www.cnblogs.com/bxzl/p/17353790.html