Java-为什么我的变量在Java中显示为0?

安德鲁布:

我是一个新的程序员,正在为课堂做作业。我正在尝试计算在不同网站上出售鞋子的利润。但是,当我尝试获取变量Fee时,输出将返回为0。请帮助谢谢!

我试图使Fee = 5;但是,输出仍然是0.0

import java.util.Scanner;

public class Shoe
{
    private double Cost;
    private double SoldPrice;
    private double ShippingCost;
    private double Fee;
    public Shoe()
    {
        Scanner input = new Scanner(System.in);
        System.out.println( " Enter Cost Of Shoe. " );
        Cost = input.nextDouble();
        System.out.println ( " Enter Sold Price Before Fees. ");
        SoldPrice = input.nextDouble();
        System.out.println ( " Enter shipping cost. " );
        ShippingCost = input.nextDouble();
        System.out.println ( " How did you sell the Shoe? [ Stockx , Ebay , Goat , Local , Grailed , Paypal  ] ? ");
//user MUST enter the provided sites perfectly.
        {
            String choice = input.next();
            if(choice.equals(" Stockx "))
            {
                Fee = 0.09;
//determinds what the value of Fee should be set to, depending on where the shoe was sold.
            }
            else if (choice.equals(" Ebay "))
            {
                Fee = (( 0.029) + 0.3 );
            }
            else if(choice.equals(" Goat "))
            {
                Fee = (( 0.095 ) + 5 );
            }
            else if(choice.equals(" Local "))
            {
                Fee = 0;
            }
            else if(choice.equals(" Grailed "))
            {
                Fee = (( 0.065 ) + 0.3 );
            }
            else if(choice.equals(" Paypal "))
            {
                Fee =(( 0.029) + 0.3 );
            }
            else if (choice.equals(" Test "))
            {
                Fee = 5;
//attempted to test if it was just rounding down for variables, however, the output was 0 when Fee was 5.
            }
            System.out.println( +Fee );
        }
    }
}
本杰明·D:

Federico klez Culloca是正确的。

删除要测试的值周围的空格,它将起作用。

为了安全起见,您甚至可以在trim()输入中使用该方法,因此即使您键入" Ebay ",它也可以使用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么从我的文件中读取的最小数字始终为0?(Java)

为什么Java中的除法displayonly为0?

为什么1月在Java日历中为0?

为什么我的Java程序中的朋友列表不显示?

为什么我们需要指针为Go / C中的变量分配值,而不是C#/ Java中的指针

Java为什么我4岁后我的for循环将i设置为0?

为什么IDEA在我的Android项目中将Java文件显示为无效?

如何在 java(OOP) 中为数组变量设置属性,在第 43 行为什么 o[0].name 不起作用?

为什么在Java中,对象成员变量不能同时为final和volatile?

为什么Java最终变量显示不可达的语句

为什么 .java 文件在 github 存储库的 src 文件夹中显示为 .class 文件?

为什么(a * b!= 0)比Java中的(a!= 0 && b!= 0)快?

为什么我不必导入Java中不用作变量类型的类?

Java-当我将值存储在变量中时为什么会作废

为什么我不能在psvm Java中创建静态最终变量?

Java为什么允许大小为0的数组?

为什么我收到错误this.variable在Java类中为null

为什么我的Java代码在Android Studio中总是将信号强度打印为零

为什么我们为与Java中的对象引用类型不同的对象分配类型?

为什么我的变量会导致Java溢出?

为什么我的变量不能用Java解析?

为什么我的变量不能用Java解析?

为什么我应该关闭java.util.Scanner变量?

为什么我不能在Lightweight Java Game Library中启动全屏显示?

为什么没有显示我的标签?(Java)

ps -al为什么不显示我的Java程序?

为什么我的try catch方法没有显示为输入的String而不是整数编写的错误消息?(Java)

为什么Java返回0?

当我尝试从自定义数组中删除元素时,为什么Java会向我显示“越界”异常?