Java程序在一台机器上运行而不在另一台机器上运行

时间:2016-10-23 20:30:59

标签: java runtime

我正在学习Java,我刚刚编写了一个程序,将大豆,小麦或玉米的CME报价转换为“巴西货币”的“每60公斤袋装价格”。我使用JSmooth来包装它,它在我的机器上完美运行。我尝试在Zip文件中将它发送到我妻子的PC,我也尝试从命令行直接调用Main类来执行它。在这两种情况下,程序一直运行到它询问USD / BRL报价的部分,然后在输入并按“Enter”后,程序显示一个明显的运行时错误:

选项:大豆/小麦/玉米

商品名称(小写):

大豆

输入当前汇率(美元/巴西雷亚尔):

3.11

Exception in thread "main" java.util.InputMismatchException
        at java.util.Scanner.throwFor(Unknown Source)
        at java.util.Scanner.next(Unknown Source)
        at java.util.Scanner.nextDouble(Unknown Source)
        at PriceCME.getExchange_Rate(PriceCME.java:26)
        at PriceCMEExecute.main(PriceCMEExecute.java:8)

我想也许她的电脑上的Java版本已经过时,所以我删除了所有以前的版本,安装了JDK 111并试图再次运行它。 同样的问题发生了。 然后我尝试在她的PC上重新编译.java文件,没有编译时错误。当我试图执行它时,同样的问题。 代码如下:

import java.util.Scanner;

public class PriceCME {
    private String nameOfCommodity;
    private final double BUSHEL_SOY_WHEAT = 27.2155;
    private final double BUSHEL_CORN = 25.4012;
    private final int KGPERSACA = 60;
    private double quote;
    private double exchRate;
    private double pricePerSaca;

        public void getNameOfComodity()
    {
        System.out.println("Options: soybean / wheat / corn");
        System.out.print("Type name of commodity(lowercase): ");
        System.out.println();
        Scanner commodity = new Scanner(System.in);
        nameOfCommodity = commodity.next();
    }

    public void getExchange_Rate()
    {
        System.out.print("Type current exchange rate(USD/BRL): ");
        System.out.println();
        Scanner exchangeRate = new Scanner(System.in);
        exchRate = exchangeRate.nextDouble();
    }

    public void getQuote()
    {
        System.out.println("Source for quotes: 
    http://www.cmegroup.com/trading/agricultural/");
        System.out.print("Type quote of commodity on CME: ");
        System.out.println();
        Scanner getQuote = new Scanner(System.in);
        quote = getQuote.nextDouble();
    }

    public void CalculatePricePerSaca()
    {
        switch(nameOfCommodity)
        {
            case "soybean":
            pricePerSaca = (((quote * KGPERSACA) / 100) / 
            BUSHEL_SOY_WHEAT) * exchRate;
            break;

            case "wheat":
            pricePerSaca = (((quote * KGPERSACA) / 100) /
            BUSHEL_SOY_WHEAT) * exchRate;
            break;

            case "corn":
            pricePerSaca = (((quote * KGPERSACA) / 100) /
            BUSHEL_CORN) * exchRate;
            break;
        }
    }

    public void getPricePerSaca()
    {
        System.out.printf("The price of %s \"Por Saca\" is:\nR$ %.2f ",
        nameOfCommodity, pricePerSaca);
        System.out.println();
        System.out.println("Type \"false\" to exit.");
        Scanner end = new Scanner(System.in);
        boolean theEnd = end.hasNext();
    }

    }

  public class PriceCMEExecute {

    public static void main(String[] args)

    {
        PriceCME myPriceCME = new PriceCME();
        myPriceCME.getNameOfComodity();
        myPriceCME.getExchange_Rate();
        myPriceCME.getQuote();
        myPriceCME.CalculatePricePerSaca();
        myPriceCME.getPricePerSaca();

    }
}

怎么会发生这种情况?它的机器上的JVM会出现问题吗?

0 个答案:

没有答案