ZZULIOJ-1102: ticket refund fee calculation (function topic) (Java)

Subject description:

Since 2013, the proportion of ticket refund fee reduction: par car station more than 48 hours before the drive time by 5% per ticket refund fee. Meanwhile, the ticket refund fee calculation method is no longer rounded to units of cells but in units of angle 5: less than 0.25 membered rounding the mantissa is not less than 0.25 and less than 0.75 membered element is 0.5 yuan, is not less than 0.75 yuan into $ 1. Write a function to calculate refunds example assumed refund driving time period more than 48 hours. Function prototype is as follows:

double CancelFee(double price);

If this question is C / C ++ code delivery submitted only CancelFee function definition part, other content submission, compile error.

 Input:

Enter a real number, the ticket face value.  

Output: 

Output a real number, the fee refund, the results to one decimal place.  

Sample input: 

106 

Sample output: 

5.5 

code: 

import java.util.*;
public class Main
{
	public static double CancelFee(double price)
	{
		double x=price*0.05;
		double y=(int)x;
		if(x-y<0.25)
			y+=0;
		else if(x-y>=0.25&&x-y<0.75)
			y+=0.5;
		else
			y+=1;
		return y;
	}
	public static void main(String[] args)
	{
		Scanner input=new Scanner(System.in);
		double a=input.nextDouble();
		System.out.printf("%.1f\n",Main.CancelFee(a));
		input.close();
	}
}

 

Published 260 original articles · won praise 267 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43823808/article/details/103747878