Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.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 使用对话框创建工程量清单(每次我尝试运行它时都会终止)?_Java_Swing - Fatal编程技术网

Java 使用对话框创建工程量清单(每次我尝试运行它时都会终止)?

Java 使用对话框创建工程量清单(每次我尝试运行它时都会终止)?,java,swing,Java,Swing,所以我一直在为这个提示挣扎一段时间。基本上,我需要使用对话框来创建一个用于建筑公司计费的程序。提示如下。第一:从单独的对话框中读取以下数据。这需要针对施工公司的名称、客户的名称、工头的工时数、工人人数、工作天数以及最终的材料成本进行。第二:必须根据从对话框中获得的信息计算以下内容。计算如下:工头人工成本=工头人工时数乘以60,工人人工成本=天数乘以每天8小时乘以工人人数乘以30美元,工作费=工头人工成本+工人人工成本+材料,折扣=工作费乘以10%,最终应付金额=工作费-折扣。最后,必须打印所有数

所以我一直在为这个提示挣扎一段时间。基本上,我需要使用对话框来创建一个用于建筑公司计费的程序。提示如下。第一:从单独的对话框中读取以下数据。这需要针对施工公司的名称、客户的名称、工头的工时数、工人人数、工作天数以及最终的材料成本进行。第二:必须根据从对话框中获得的信息计算以下内容。计算如下:工头人工成本=工头人工时数乘以60,工人人工成本=天数乘以每天8小时乘以工人人数乘以30美元,工作费=工头人工成本+工人人工成本+材料,折扣=工作费乘以10%,最终应付金额=工作费-折扣。最后,必须打印所有数据。输出应类似于建筑公司名称,客户:xxxxx,天数=xxxxx,工头人工成本=xxxxx,工人人工成本=xxxxx,材料成本=xxxxx,工作费=xxxxx,折扣=xxxxx,最终到期金额=xxxxx。我的问题是,我无法使用对话框中的信息运行代码以生成所需的输出?每次我尝试运行该程序时,它都会被终止,因此我有点困惑,因为我对Java相当陌生,因此希望您能提供任何帮助。到目前为止,我拥有的代码如下:

package bill;
import javax.swing.JOptionPane;
public class ContractorBill 
{
public static void main(String[]args) {
    }
double forhours,workers,daysonjob,costofmaterials,flcost,wlcost,jobfee,discount,finalamount;
String fname,cname,forstring,wstring,dojstring,comstring,printdata="";{

fname=JOptionPane.showInputDialog(null,"Enter the name of the construction firm","Input Data",JOptionPane.QUESTION_MESSAGE);
cname=JOptionPane.showInputDialog(null,"Enter the customer's name","Input Data",JOptionPane.QUESTION_MESSAGE);
forstring=JOptionPane.showInputDialog(null,"Enter the number of labor hours required for the foreman","Input",JOptionPane.QUESTION_MESSAGE);
wstring=JOptionPane.showInputDialog(null, "Enter the number of workers required","Input",JOptionPane.QUESTION_MESSAGE);
dojstring=JOptionPane.showInputDialog(null,"Enter the number of days required to complete the job","Input",JOptionPane.QUESTION_MESSAGE);
comstring=JOptionPane.showInputDialog(null,"Enter the cost of materials required for the job"+"Input",JOptionPane.QUESTION_MESSAGE);

forhours=Double.parseDouble(forstring);
workers=Double.parseDouble(wstring);
daysonjob=Double.parseDouble(dojstring);
costofmaterials=Double.parseDouble(comstring);

flcost=60*(forhours);
wlcost=8*(daysonjob)+30*(workers);
jobfee=(flcost)+(wlcost)+(costofmaterials);
discount=(jobfee)*0.10;
finalamount=(jobfee)-(discount);

printdata=printdata+"CONSTRUCTION FIRM NAME="+fname+"\n"+
"CUSTOMER:"+cname+"\n"+
"Number of days ="+daysonjob+"\n"+
"Forman labor cost ="+flcost+"\n"+
"Worker Labor Cost ="+wlcost+"\n"+
"Materials cost ="+costofmaterials+"\n"+
"Job Fee ="+jobfee+"\n"+
"Discount ="+discount+"\n"+
"Final Amount Due ="+finalamount+"\n";
JOptionPane.showMessageDialog(null,printdata,"Output:",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);

}}

main
方法是唯一一个自动调用的方法,并且它不包含会导致它不立即终止的语句

请参阅此修改后的版本,并仔细阅读代码注释:

import javax.swing.JOptionPane;

public class ContractorBill {

    double forhours, workers, daysonjob, costofmaterials, flcost, wlcost, jobfee, discount, finalamount;
    String fname, cname, forstring, wstring, dojstring, comstring, printdata = "";

    public static void main(String[] args) {
        new ContractorBill(); // call the (newly added) constructor
    }

    // this has now been turned from a code block into a constructor
    ContractorBill() { 

        fname = JOptionPane.showInputDialog(null, "Enter the name of the construction firm", "Input Data", JOptionPane.QUESTION_MESSAGE);
        cname = JOptionPane.showInputDialog(null, "Enter the customer's name", "Input Data", JOptionPane.QUESTION_MESSAGE);
        forstring = JOptionPane.showInputDialog(null, "Enter the number of labor hours required for the foreman", "Input", JOptionPane.QUESTION_MESSAGE);
        wstring = JOptionPane.showInputDialog(null, "Enter the number of workers required", "Input", JOptionPane.QUESTION_MESSAGE);
        dojstring = JOptionPane.showInputDialog(null, "Enter the number of days required to complete the job", "Input", JOptionPane.QUESTION_MESSAGE);
        comstring = JOptionPane.showInputDialog(null, "Enter the cost of materials required for the job" + "Input", JOptionPane.QUESTION_MESSAGE);

        forhours = Double.parseDouble(forstring);
        workers = Double.parseDouble(wstring);
        daysonjob = Double.parseDouble(dojstring);
        costofmaterials = Double.parseDouble(comstring);

        flcost = 60 * (forhours);
        wlcost = 8 * (daysonjob) + 30 * (workers);
        jobfee = (flcost) + (wlcost) + (costofmaterials);
        discount = (jobfee) * 0.10;
        finalamount = (jobfee) - (discount);

        printdata = printdata + "CONSTRUCTION FIRM NAME=" + fname + "\n"
                + "CUSTOMER:" + cname + "\n"
                + "Number of days =" + daysonjob + "\n"
                + "Forman labor cost =" + flcost + "\n"
                + "Worker Labor Cost =" + wlcost + "\n"
                + "Materials cost =" + costofmaterials + "\n"
                + "Job Fee =" + jobfee + "\n"
                + "Discount =" + discount + "\n"
                + "Final Amount Due =" + finalamount + "\n";
        JOptionPane.showMessageDialog(null, printdata, "Output:", JOptionPane.INFORMATION_MESSAGE);
        System.exit(0);
    }
}

那么,你的问题是什么?您已经列出了三个需求,并展示了一些代码,但没有说明您的困境。请参阅:在问题主体中,首先展开标题中的摘要。解释你是如何遇到你试图解决的问题的,以及任何阻碍你自己解决问题的困难。我们不知道你的困难在哪里。另外,这里的问题格式是这样的,如果你有三个单独的问题,请发三篇帖子。