Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 排序系统中的catch块_Java_Eclipse - Fatal编程技术网

Java 排序系统中的catch块

Java 排序系统中的catch块,java,eclipse,Java,Eclipse,我正在制作一个订购系统。如果没有为数量输入值,我需要它抛出一个错误。我是一个初学者,但我仍然坚持使用IDE而不是学习基础知识。这是我的密码: /** * Course: IT110 - Introduction to Programming * Filename: NMPTireShopPhase1.java * Created: 04/09/10 by Dr. Debby Telfer * Modified: 11/26/13 by Dr. Bary W Pollack * M

我正在制作一个订购系统。如果没有为数量输入值,我需要它抛出一个错误。我是一个初学者,但我仍然坚持使用IDE而不是学习基础知识。这是我的密码:

/**
 * Course:   IT110 - Introduction to Programming
 * Filename: NMPTireShopPhase1.java
 * Created:  04/09/10 by Dr. Debby Telfer
 * Modified: 11/26/13 by Dr. Bary W Pollack
 * Modified: 10/14/14 by Michael Hodges
 * Purpose:  Created a simple online ordering system
 *           for NMP Tire Shop customers
 */

import javax.swing.JOptionPane;

import java.sql.Statement;
import java.util.InputMismatchException;

/**
 * @author bary
 * @author Mike
 */
class NMPTireShopPhase1 {

    private static final boolean InputMismatchException = false;
    private static final boolean AssignmentOperatorExpression = false;



    /**
     * @param args
     */

    public static void main(String[] args) {

        // declare variables
        String openingMsg, nameInputMsg, customerName, nameOutputMsg, 
               returnInputMsg, customerReturn, returnOutputMsg,
               typeInputMsg, typeReturn, typeOutputMsg,
 quantityInputMsg, quantityReturn, quantityOutputMsg,
               greetingOutputMsg, outputMsg;

        // display opening message
        openingMsg = "*** Welcome to NMP Tire Shop Online Ordering System ***\n"
                   + "                     Allow us to fix your tires!";
        JOptionPane.showMessageDialog(null, openingMsg);

        // get required input using dialogs
        nameInputMsg   = "Please enter your name: ";
        String prompt = JOptionPane.showInputDialog(nameInputMsg );
        customerName   = getStringInput11(prompt );
        returnInputMsg = "please state what vehichle your tire is for: ";
        String prompt1 = JOptionPane.showInputDialog(returnInputMsg);
        customerReturn = getStringInput11(prompt1 );
        typeInputMsg   = "please state the type of rim: ";
        String prompt2 = JOptionPane.showInputDialog(typeInputMsg);
        typeReturn = getStringInput11(prompt2);
        quantityInputMsg = "how many tires do you want repaired?(1-99)";
        String prompt3 = JOptionPane.showInputDialog(quantityInputMsg);
        System.out.println("enter your quantity");
        System.out.println(quantityInputMsg);
        quantityReturn = getStringInput11(prompt3);

        // build output strings
        nameOutputMsg     = "Welcome " + customerName + ".\n\n";
        returnOutputMsg   = " Your tire is for a " + customerReturn + ".\n\n" ;
        typeOutputMsg     = " Your rim type is " + typeReturn + ".\n\n" ;
        quantityOutputMsg = " You want this many tires repaired " + quantityReturn +".\n\n";
        greetingOutputMsg = " Thank you for visiting NMP Tire Shop!" + "\n\n"
                          + "Your tires should be returned in less than a month.\n";

        // create and display output string
        outputMsg = (nameOutputMsg + returnOutputMsg + typeOutputMsg + quantityOutputMsg + greetingOutputMsg);
        JOptionPane.showMessageDialog(null, outputMsg);

        System.exit(0);
    } // end main()
    {
    catch(InputMismatchException) Statement AssignmentOperatorExpression; (InputMismatchException);
    {
        System.out.println("pleas enter numerical value only.");
        System.exit(3);}
    }



    private static String getStringInput11(String quantityInputMsg) {
        // TODO Auto-generated method stub
        return quantityInputMsg;

    }



    private void AssignmentOperatorExpression(boolean inputmismatchexception2) {
        // TODO Auto-generated method stub

    }

    }

 // end class NMPTireShopPhase1

我不知道捕获是否在错误的地方,但它甚至不会运行。我需要它捕捉错误并允许在终止程序之前进行三次尝试。这是正确的方法吗?我只是缺少了一个命令,还是它放在了完全错误的位置?

catch语法应该是这样的

} catch (InputMismatchException e) {
  System.out.println("pleas enter numerical value only.");
  e.printStackTrace(); // <-- Please don't swallow the exception.
  System.exit(3);
}
} catch (IOException|InputMismatchException e) {
  System.out.println("pleas enter numerical value only.");
  e.printStackTrace(); // <-- Please don't swallow the exception.
  System.exit(3);
}
}捕获(输入不匹配异常e){
System.out.println(“请仅输入数值”);
e、 printStackTrace()//