Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.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市场实验室gui_Java - Fatal编程技术网

Java市场实验室gui

Java市场实验室gui,java,Java,我已经在这个java程序上工作了一段时间,但是我遇到了麻烦,我需要帮助。我运行这个程序,除了优惠券按钮,其他一切都正常工作。好吧,它是有效的,但是当我使用一个大于总价格的优惠券号码时,它会显示一个负数。我需要帮助,使它成为一个零出现时,更高的优惠券号码输入。我想我必须编写这样的循环(如果bill

我已经在这个java程序上工作了一段时间,但是我遇到了麻烦,我需要帮助。我运行这个程序,除了优惠券按钮,其他一切都正常工作。好吧,它是有效的,但是当我使用一个大于总价格的优惠券号码时,它会显示一个负数。我需要帮助,使它成为一个零出现时,更高的优惠券号码输入。我想我必须编写这样的循环(如果bill<0){str=“0”}。代码链接如下


您在bill var中有逻辑错误;据我所知,优惠券应该有许多项目,但每张优惠券只有一张账单,对吗?因此,请不要将bill var作为本地字段,因为它会在每次事件发生时重新初始化bill;因此,要使其迭代数据生成类字段,请参见示例:

问题代码

...
public void actionPerformed(ActionEvent e)
    {
    String str;
    String couponReciept;
    String coupontest;
    int couponnumber;
    int marketnumber;
    double price;
    double bill = 0; //<---logical error "local field"
    DecimalFormat output = new DecimalFormat("0.00");
    index = grocery.getSelectedIndex();


    price = groceryprice[index];

    System.out.print("Cost = " + price + "$ ");

    str = quanityText.getText();
    marketnumber = Integer.parseInt(str);
    bill = marketnumber * price;


    if (couponyes.isSelected())
   {

    coupontest = couponText.getText();
    couponnumber = Integer.parseInt(coupontest);

    bill = bill - couponnumber;

   }
  ... 
...
double bill = 0;
public void actionPerformed(ActionEvent e)
    {
    String str;
    String couponReciept;
    String coupontest;
    int couponnumber;
    int marketnumber;
    double price;

    DecimalFormat output = new DecimalFormat("0.00");
    index = grocery.getSelectedIndex();


    price = groceryprice[index];

    System.out.print("Cost = " + price + "$ ");

    str = quanityText.getText();
    marketnumber = Integer.parseInt(str);
    bill = marketnumber * price;


    if (couponyes.isSelected())
   {

    coupontest = couponText.getText();
    couponnumber = Integer.parseInt(coupontest);

    bill = bill - couponnumber;

   }
  ...
我不确定它是否能修复整个代码;但从某些方面来说,它或多或少是解决你的具体问题的方法


祝您好运

请提供如何测试code.JCreator。你所需要的只是链接中的文件和一个名为“final.txt”的文本文档,其中包含此信息—(如果你们不介意,我可以将zip文件发布到某个地方,请编辑你的问题以包含代码,而不仅仅是指向它的链接。