2014-12-08 51 views
0

我一直在研究这个java程序一段时间,但我碰到了墙壁,我需要帮助。我运行这个程序,除了优惠券按钮之外,一切都按照原样运行。那么它的作品,但是当我使用大于总价格的优惠券号码时,它显示一个负数。我需要帮助,以便在输入更高的优惠券号码时显示零。我想我必须写一个循环(如果bill < 0){str =“0”}。代码链接如下。Java市场实验室gui

http://codepad.org/EhLICVGT

+0

请提供如何测试代码。 – 2014-12-08 07:09:39

+0

JCreator。所有你需要的是链接中的文件和一个名为“final.txt”的文本文件,其中包含这些信息 - http://textuploader.com/oidq (如果你们不介意我可以在某处发布zip文件 – Rockstarhero 2014-12-08 07:20:43

+0

请修改您的问题以包含代码,而不仅仅是一个链接。 – 2014-12-08 08:23:52

回答

0

你在账单VAR逻辑错误;我可以得到它,优惠券必须有许多项目但每个优惠券只有一个账单吗?所以请不要做帐单var作为本地字段导致其每次发生事件时都要重新登录帐单;因此,为了使重复数据使类字段中看到例如:

问题代码

... 
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; 

    } 
    ... 

我不知道将它修复整个代码;但在某些方面,它是修复或多或少您的具体问题的问题

好运的方式