Java Can';我的菜单无法打开

Java Can';我的菜单无法打开,java,Java,理想情况下,我希望我的程序打开与数字对应的方法。 我这样做是为了学校,不明白为什么代码不能按预期工作 任何帮助都将不胜感激,我希望能及时得到答复 import java.io.*; public class Javavison { static String name[]=new String[10000]; static int time[]=new int[10000]; static int day []=new int[10000]; static int positionCounte

理想情况下,我希望我的程序打开与数字对应的方法。 我这样做是为了学校,不明白为什么代码不能按预期工作

任何帮助都将不胜感激,我希望能及时得到答复

import java.io.*;
public class Javavison {

static String name[]=new String[10000];
static int time[]=new int[10000];
static int day []=new int[10000];
static int positionCounter=0;

public static void main(String args[]) throws IOException {
    int menuChoice=1;
    System.out.println("Hello and Welcome to Javavision");
    while(menuChoice!=6){
        System.out.println("Enter Menu Choice");
        System.out.println("(1) Enter TV Shows/Add a TV Show");
        System.out.println("(2) Modify TV Show");
        System.out.println("(3) Delete TV Show");
        System.out.println("(4) Sort TV Shows");
        System.out.println("(5) Show all TV Shows");
        System.out.println("(6) Exit Program");

        BufferedReader in;
        in=new BufferedReader(new InputStreamReader(System.in));
        try{
            menuChoice=in.read();
        }
        catch(IOException ie) {
             ie.printStackTrace();
        }

        if(menuChoice==1){
            addShow();
        }
        if(menuChoice==2){
            modShow();
        }
        if(menuChoice==3){
            deleteShow();
        }
        if(menuChoice==4){
            sortShow();
        }
        if(menuChoice==5){
            showShows();
        }
        if(menuChoice==6){
            break;
        }
    }
}

public static void addShow(){
    positionCounter++;
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter Name of Show");
    try{
        name[positionCounter]=in.readLine();
    }
    catch(IOException ie) {
     ie.printStackTrace();
    }
    System.out.println("Enter Day of Show");
    try{
        day[positionCounter]=in.read();
    }
    catch(IOException ie) {
     ie.printStackTrace();
    }
    System.out.println("Enter Time of Show(In military time, For example 2:30am=0230");
    try{
        time[positionCounter]=in.read();
    }
    catch(IOException ie) {
     ie.printStackTrace();
    }

}

public static void modShow() throws IOException{
    String name[]=new String[2];
    int forLoopCounter=0;
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter Name of Show that you would like to modify");
    try{
        name[1]=in.readLine();
    }
    catch(IOException ie) {
     ie.printStackTrace();
    }

    for(int a=1; a<=positionCounter;a++){
        forLoopCounter=a;
        if(name[1].compareTo(name[a]) ==0){
            a=positionCounter+2;
        }
    }
    if(forLoopCounter!=(positionCounter+1)){
        //allow user to modify information because name has been found
        System.out.println("Enter New Name: ");
        name[positionCounter] = in.readLine();
        System.out.println("Enter New Time: ");
        time[positionCounter] = Integer.valueOf(in.readLine()).intValue();
        System.out.println("Enter New Day: ");
        day[positionCounter] = Integer.valueOf(in.readLine()).intValue();
    }
    else{
        //tell the user the name he entered is not in the data list
        System.out.println("Sorry The show you requested is not available");
    }
}

public static void deleteShow(){
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));

}

public static void sortShow(){
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));

}

public static void showShows(){
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));
}
}
import java.io.*;
公共类Javavison{
静态字符串名称[]=新字符串[10000];
静态整数时间[]=新整数[10000];
静态整数日[]=新整数[10000];
静态int位置计数器=0;
公共静态void main(字符串args[])引发IOException{
int menuChoice=1;
System.out.println(“您好,欢迎来到Javavision”);
while(menuChoice!=6){
System.out.println(“输入菜单选项”);
System.out.println(“(1)输入电视节目/添加电视节目”);
System.out.println(“(2)修改电视节目”);
System.out.println(“(3)删除电视节目”);
System.out.println(“(4)对电视节目进行排序”);
System.out.println(“(5)显示所有电视节目”);
System.out.println(“(6)退出程序”);
缓冲读取器;
in=新的BufferedReader(新的InputStreamReader(System.in));
试一试{
menuChoice=in.read();
}
捕获(IOIE){
即printStackTrace();
}
如果(menuChoice==1){
addShow();
}
如果(menuChoice==2){
modShow();
}
如果(menuChoice==3){
deleteShow();
}
如果(menuChoice==4){
sortShow();
}
如果(menuChoice==5){
showShows();
}
如果(menuChoice==6){
打破
}
}
}
公共静态void addShow(){
位置计数器++;
缓冲读取器;
in=新的BufferedReader(新的InputStreamReader(System.in));
System.out.println(“输入节目名称”);
试一试{
名称[positionCounter]=in.readLine();
}
捕获(IOIE){
即printStackTrace();
}
System.out.println(“输入显示日期”);
试一试{
日期[位置计数器]=in.read();
}
捕获(IOIE){
即printStackTrace();
}
System.out.println(“输入显示时间(以军事时间为单位,例如2:30am=0230”);
试一试{
时间[位置计数器]=in.read();
}
捕获(IOIE){
即printStackTrace();
}
}
公共静态void modShow()引发IOException{
字符串名称[]=新字符串[2];
int-forLoopCounter=0;
缓冲读取器;
in=新的BufferedReader(新的InputStreamReader(System.in));
System.out.println(“输入要修改的节目名称”);
试一试{
名称[1]=in.readLine();
}
捕获(IOIE){
即printStackTrace();
}

对于(int a=1;a将BufferedReader更改为Scanner。您的BufferedReader没有读取整数

import java.util.*;
import java.io.*;
public class Javavison {

static String name[]=new String[10000];
static int time[]=new int[10000];
static int day []=new int[10000];
static int positionCounter=0;

public static void main(String args[]) throws IOException {
    int menuChoice=1;
    System.out.println("Hello and Welcome to Javavision");
    while(menuChoice!=6){
        System.out.println("Enter Menu Choice");
        System.out.println("(1) Enter TV Shows/Add a TV Show");
        System.out.println("(2) Modify TV Show");
        System.out.println("(3) Delete TV Show");
        System.out.println("(4) Sort TV Shows");
        System.out.println("(5) Show all TV Shows");
        System.out.println("(6) Exit Program");

        Scanner scn = new Scanner(System.in);
        menuChoice=scn.nextInt();

        if(menuChoice==1){
            addShow();
        }
        else if(menuChoice==2){
            modShow();
        }
        else if(menuChoice==3){
            deleteShow();
        }
        else if(menuChoice==4){
            sortShow();
        }
        else if(menuChoice==5){
            showShows();
        }
        else if(menuChoice==6){
            break;
        }
    }
}

public static void addShow(){
    positionCounter++;
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter Name of Show");
    try{
        name[positionCounter]=in.readLine();
    }
    catch(IOException ie) {
     ie.printStackTrace();
    }
    System.out.println("Enter Day of Show");
    try{
        day[positionCounter]=in.read();
    }
    catch(IOException ie) {
     ie.printStackTrace();
    }
    System.out.println("Enter Time of Show(In military time, For example 2:30am=0230");
    try{
        time[positionCounter]=in.read();
    }
    catch(IOException ie) {
     ie.printStackTrace();
    }

}

public static void modShow() throws IOException{
    String name[]=new String[2];
    int forLoopCounter=0;
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter Name of Show that you would like to modify");
    try{
        name[1]=in.readLine();
    }
    catch(IOException ie) {
     ie.printStackTrace();
    }

    for(int a=1; a<=positionCounter;a++){
        forLoopCounter=a;
        if(name[1].compareTo(name[a]) ==0){
            a=positionCounter+2;
        }
    }
    if(forLoopCounter!=(positionCounter+1)){
        //allow user to modify information because name has been found
        System.out.println("Enter New Name: ");
        name[positionCounter] = in.readLine();
        System.out.println("Enter New Time: ");
        time[positionCounter] = Integer.valueOf(in.readLine()).intValue();
        System.out.println("Enter New Day: ");
        day[positionCounter] = Integer.valueOf(in.readLine()).intValue();
    }
    else{
        //tell the user the name he entered is not in the data list
        System.out.println("Sorry The show you requested is not available");
    }
}

public static void deleteShow(){
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));

}

public static void sortShow(){
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));

}

public static void showShows(){
    BufferedReader in;
    in=new BufferedReader(new InputStreamReader(System.in));
}
}
import java.util.*;
导入java.io.*;
公共类Javavison{
静态字符串名称[]=新字符串[10000];
静态整数时间[]=新整数[10000];
静态整数日[]=新整数[10000];
静态int位置计数器=0;
公共静态void main(字符串args[])引发IOException{
int menuChoice=1;
System.out.println(“您好,欢迎来到Javavision”);
while(menuChoice!=6){
System.out.println(“输入菜单选项”);
System.out.println(“(1)输入电视节目/添加电视节目”);
System.out.println(“(2)修改电视节目”);
System.out.println(“(3)删除电视节目”);
System.out.println(“(4)对电视节目进行排序”);
System.out.println(“(5)显示所有电视节目”);
System.out.println(“(6)退出程序”);
扫描仪scn=新扫描仪(System.in);
menuChoice=scn.nextInt();
如果(menuChoice==1){
addShow();
}
else if(menuChoice==2){
modShow();
}
else if(menuChoice==3){
deleteShow();
}
else if(menuChoice==4){
sortShow();
}
else if(menuChoice==5){
showShows();
}
else if(menuChoice==6){
打破
}
}
}
公共静态void addShow(){
位置计数器++;
缓冲读取器;
in=新的BufferedReader(新的InputStreamReader(System.in));
System.out.println(“输入节目名称”);
试一试{
名称[positionCounter]=in.readLine();
}
捕获(IOIE){
即printStackTrace();
}
System.out.println(“输入显示日期”);
试一试{
日期[位置计数器]=in.read();
}
捕获(IOIE){
即printStackTrace();
}
System.out.println(“输入显示时间(以军事时间为单位,例如2:30am=0230”);
试一试{
时间[位置计数器]=in.read();
}
捕获(IOIE){
即printStackTrace();
}
}
公共静态void modShow()引发IOException{
字符串名称[]=新字符串[2];
int-forLoopCounter=0;
缓冲读取器;
in=新的BufferedReader(新的InputStreamReader(System.in));
System.out.println(“输入要修改的节目名称”);
试一试{
名称[1]=in.readLine();
}
捕获(IOIE){
即printStackTrace();
}

对于(int a=1;a而言,错误在于使用in.read()获取菜单。 InputStream.read()返回输入的第一个字节,而不是整行,我已将.read()中的替换为整数.parseInt(in.readLine())。此外,我还冒昧地用开关替换了ifs

现在它开始工作了

import java.io.*;

public class Javavison {

    static String name[] = new String[10000];
    static int time[] = new int[10000];
    static int day[] = new int[10000];
    static int positionCounter = 0;

    public static void main(String args[]) throws IOException {
        int menuChoice = 1;
        System.out.println("Hello and Welcome to Javavision");
        while (menuChoice != 6) {
            System.out.println("Enter Menu Choice");
            System.out.println("(1) Enter TV Shows/Add a TV Show");
            System.out.println("(2) Modify TV Show");
            System.out.println("(3) Delete TV Show");
            System.out.println("(4) Sort TV Shows");
            System.out.println("(5) Show all TV Shows");
            System.out.println("(6) Exit Program");

            BufferedReader in;
            in = new BufferedReader(new InputStreamReader(System.in));
            try {
                menuChoice = Integer.parseInt(in.readLine());
            } catch (IOException ie) {
                ie.printStackTrace();
            }

            switch(menuChoice) {
                case 1:
                    addShow();
                    break;
                case 2:
                    modShow();
                    break;
                case 3:
                    deleteShow();
                    break;
                case 4:
                    sortShow();
                    break;
                case 5:
                    showShows();
                    break;
                case 6:
                    return;
            }

        }
    }

    public static void addShow() {
        positionCounter++;
        BufferedReader in;
        in = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter Name of Show");
        try {
            name[positionCounter] = in.readLine();
        } catch (IOException ie) {
            ie.printStackTrace();
        }
        System.out.println("Enter Day of Show");
        try {
            day[positionCounter] = Integer.parseInt(in.readLine());
        } catch (IOException ie) {
            ie.printStackTrace();
        }
        System.out.println("Enter Time of Show(In military time, For example 2:30am=0230");
        try {
            time[positionCounter] = Integer.parseInt(in.readLine());
        } catch (IOException ie) {
            ie.printStackTrace();
        }

    }

    public static void modShow() throws IOException {
        String name[] = new String[2];
        int forLoopCounter = 0;
        BufferedReader in;
        in = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter Name of Show that you would like to modify");
        try {
            name[1] = in.readLine();
        } catch (IOException ie) {
            ie.printStackTrace();
        }

        for (int a = 1; a <= positionCounter; a++) {
            forLoopCounter = a;
            if (name[1].compareTo(name[a]) == 0) {
                a = positionCounter + 2;
            }
        }
        if (forLoopCounter != (positionCounter + 1)) {
            // allow user to modify information because name has been found
            System.out.println("Enter New Name: ");
            name[positionCounter] = in.readLine();
            System.out.println("Enter New Time: ");
            time[positionCounter] = Integer.valueOf(in.readLine()).intValue();
            System.out.println("Enter New Day: ");
            day[positionCounter] = Integer.valueOf(in.readLine()).intValue();
        } else {
            // tell the user the name he entered is not in the data list
            System.out.println("Sorry The show you requested is not available");
        }
    }

    public static void deleteShow() {
        BufferedReader in;
        in = new BufferedReader(new InputStreamReader(System.in));

    }

    public static void sortShow() {
        BufferedReader in;
        in = new BufferedReader(new InputStreamReader(System.in));

    }

    public static void showShows() {
        BufferedReader in;
        in = new BufferedReader(new InputStreamReader(System.in));
    }
}
import java.io.*;
公共类Javavison{
静态字符串名称[]=新字符串[10000];
静态整数时间[]=新整数[10000];
静态整数日[]=新整数[10000];
静态int位置计数器=0;
公共静态void main(字符串args[])引发IOException{
int menuChoice=1;
System.out.println(“您好,欢迎来到Javavision”);
while(menuChoice!=6){
System.out.println(“输入菜单选项”);
System.out.println(“(1)输入电视节目/添加电视节目”);
System.out.println(“(2)修改电视节目”);
System.out.println(“(3)删除电视节目”);