需要帮助调试我的java任务 [英] Need help debugging my java assignment

查看:60
本文介绍了需要帮助调试我的java任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import javax.swing.JOptionPane;


public class Text

	{
		public static void main(String[] args)
		{
		String amount;
		double stateSalesTax;
		double countySalesTax;
		double totalSalesTax;
		double totalSalesAmount;
		double amt;
		JOptionPane.showInputDialog("Enter the amount of purchase");
		amt = Double.parseDouble(amount);
		
		stateSalesTax = 0.055;
		countySalesTax = 0.02;
		totalSalesTax = stateSalesTax + countySalesTax;
		totalSalesAmount = amt + totalSalesTax;
		
		JOptionPane.showMessageDialog (null, "The purchase amount is: " + amt + 
										"The state sales tax is:" + stateSalesTax + 
										"The county sales tax is:" + countySalesTax +
										"The total amount of sales is:" + totalSalesAmount);
		}
	}





命令提示符告诉我我的问题在于读取amt = Double.parseDouble的行(金额);



我尝试过:



我有尝试使用强制转换操作符来告诉程序字符串类型可以与double类型共存,但是,它无济于事。



Command prompt tells me my problem is on the line that reads amt = Double.parseDouble(amount);

What I have tried:

I have tried to use a cast operator to tell the program that the string type can coexist with the double type, but alas, it was to no avail.

推荐答案

使用调试器查看错误位置金额的值是多少。

Use the debugger to see what is the value of amount at error position.
引用:

我曾尝试使用强制转换操作符来告诉程序字符串类型可以与double类型共存,但是唉,它无济于事。

I have tried to use a cast operator to tell the program that the string type can coexist with the double type, but alas, it was to no avail.

显然,你不明白它是如何工作的,需要进一步研究。





你应该学会尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]

http: //docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your -first-java-application.html [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较do。

Obviously, you don't understand how it works, further study is in order.


You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.


这是工作代码。

未定义两个错误数量,第二个是您需要导入javax.swing.JOptionPane;



Here is working code.
Two errors amount is not defined and second thing is that you need to import javax.swing.JOptionPane;

<pre lang="java">
import javax.swing.JOptionPane;

public class Text {

    public static void main(String[] args) {
        String amount;
        double stateSalesTax;
        double countySalesTax;
        double totalSalesTax;
        double totalSalesAmount;
        double amt;
        amount = JOptionPane.showInputDialog("Enter the amount of purchase");
        amt = Double.parseDouble(amount);

        stateSalesTax = 0.055;
        countySalesTax = 0.02;
        totalSalesTax = stateSalesTax + countySalesTax;
        totalSalesAmount = amt + totalSalesTax;

        JOptionPane.showMessageDialog(null, "The purchase amount is: " + amt
                + "The state sales tax is:" + stateSalesTax
                + "The county sales tax is:" + countySalesTax
                + "The total amount of sales is:" + totalSalesAmount);
    }
}


这篇关于需要帮助调试我的java任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆