2015-03-03 34 views
1

嗨,基本上我需要写一个方法来计算衬衫的价格前10个衬衫订购的收费为每件衬衫20美元,然后任何衬衫收取每件衬衫15美元。任何人都可以帮助我解决这个问题,这是我迄今为止感谢的。坚持写一个简单的方法,如果说明

public static double calculateCost(int ShirtsOrdered) { 
    double cost = 0.0; 

    if (ShirtsOrdered <= 10) { 
     cost = cost + 20.00 * ((ShirtsOrdered)/1); 


    } else if ((ShirtsOrdered > 10) { 
     cost = cost + 15.00 * ((ShirtsOrdered)/1); 



    return cost; 
} 
+0

'成本= 15.0 * ShirtsOrdered' ...? – MadProgrammer 2015-03-03 02:34:23

+1

除以一个没有意义.. – 2015-03-03 02:35:24

回答

4

最短的解决办法是:

public static double calculateCost(int ShirtsOrdered) { 
    if (ShirtsOrdered > 10){ 
     return 200.0 + (ShirtsOrdered - 10) * 15.0; 
    } 
    return ShirtsOrdered * 20.0; 
} 
1

您必须算多少衬衫后10

public static double calculateCost(int ShirtsOrdered) { 
    double cost = 0.0; 

    if (ShirtsOrdered <= 10) { 
     cost = cost + 20.00 * ((ShirtsOrdered)/1); 


    } else if ((ShirtsOrdered > 10) { 
     cost = cost + 20.00 * (10/1);//<-- here the cost for 10 first shirt 
     cost = cost + 15.00 * ((ShirtsOrdered-10)/1); //<-- here make the count 



    return cost; 
}