//Java实现KTV点歌台基础功能
import java.util.*;
public class KTV
{
public static void main(String[] args)
{
System.out.println("欢迎来到点歌系统");
System.out.println("0.添加歌曲");
System.out.println("1.将歌曲置顶");
System.out.println("2.将歌曲前移一位");
System.out.println("3.退出");
LinkedList<String> link = new LinkedList<String>();
//添加歌单初始歌曲
link.add("fade");
link.add("sing for you");
link.add("i really like you");
link.add("Angel of eyes");
//每次都执行一次命令,并输出当前歌单
while (true)
{
SongMenu(link);
switch (input())
{
case 0:Addmusic(link);break;
case 1:Topmusic(link);break;
case 2:Beforemusic(link);break;
case 3:System.out.println("你已退出点歌");return;
}
}
}
//输出歌单歌曲
public static void SongMenu(LinkedList<String> link){
System.out.println("当前歌单为:"+link);
System.out.println("请输入要执行的操作序号:");
}
//执行输入歌曲命令
public static int input(){
Scanner S = new Scanner(System.in);
return S.nextInt();
}
//执行添加歌曲命令
public static void Addmusic(LinkedList<String> link){
System.out.println("请输入要添加的歌曲名称:");
Scanner scanner = new Scanner(System.in);
link.add(scanner.next());
System.out.println("已添加歌曲"+link.getLast());
}
//执行置顶歌曲的命令
public static void Topmusic(LinkedList<String> link){
System.out.println("请输入要置顶的歌曲:");
String name = new Scanner(System.in).nextLine();
//nextLine()------将此扫描仪扫描到当前行,并返回跳过的输入。
//Scanner S = new Scanner(System.in);
//String name = S.next();
if (!link.contains(name))
{
System.out.println("您输入的歌曲不在当前列表中!");
}else{
if (link.indexOf(name) == 0)
{
System.out.println("当前歌曲已经置顶");
}else{
link.remove(name);
link.add(0,name);
System.out.println("已置顶!");
}
}
}
//执行置前歌曲的命令
public static void Beforemusic(LinkedList<String> link){
System.out.println("请输入要置前的歌曲名称:");
String name = new Scanner(System.in).nextLine();
//nextLine()------将此扫描仪扫描到当前行,并返回跳过的输入。
//Scanner S = new Scanner(System.in);
//String name = S.next();
int i = link.indexOf(name);
if (i < 0)
{
System.out.println("您输入的歌曲不在当前列表中!");
}else{
if (i == 0)
{
System.out.println("当前歌曲已经置顶");
}else{
link.remove(i);
link.add(i-1,name);
}
}
}
}