我是一个新的程序员,正在为课堂做作业。我正在尝试计算在不同网站上出售鞋子的利润。但是,当我尝试获取变量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 );
}
}
}
Federico klez Culloca是正确的。
删除要测试的值周围的空格,它将起作用。
为了安全起见,您甚至可以在trim()
输入中使用该方法,因此即使您键入" Ebay "
,它也可以使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句