Write your code in the file PayFriend.java. Use the IO module to read inputs and
ID: 3926289 • Letter: W
Question
Write your code in the file PayFriend.java. Use the IO module to read inputs and output answers.
You work for the a payment processing service called PayFriend. PayFriend charges money receivers the following fees
The first $100 has a flat fee of $5.
Payments over $100 (but under $1000) have a fee of 3% or $6, whichever is higher.
Payments $1,000 (but under $10,000) and over have a fee of 1% or $15, whichever is higher.
Payments $10,000 and over are subject to fees as follows:
The first $10,000 have a fee of 1%
The next $5,000 have an additional fee of 2%
Anything more will demand an additional fee of 3%
For example, an payment of $40,000 would be subject to $950 fee: 1% on the first $10,000 ($100 fee), 2% on the next $5,000 ($100 fee), and 3% on the last $25,000 ($750 tax).
Ask the user for their payment amount (real number) and compute the amount of the fee that they owe (real number).
Example:
Explanation / Answer
import java.util.*; // importing scanner from util
public class PayFriend {
public static void main(String[] args) {
int realnumber;
float fee;
System.out.println("Enter payment amount:");
Scanner scan = new Scanner(System.in);// creating scan object from Scanner class
int payment=scan.nextInt(); // declaring amount variable and taking input from user
System.out.println("Amount you have entered: "+payment);
if(payment<=100){ //
System.out.println("Amount of the fee that they owe (real number): $"+5);
}else if(payment>100 && payment<1000){
fee =(payment*3)/100.0f; /* if you try (payment*3)/100, will get only 13.0,
if we can use 100.0f can get percentage value in decimal*/
if(fee>6){
System.out.println("Amount of the fee that they owe (real number): $"+fee);
}else{
System.out.println("Amount of the fee that they owe (real number): $"+6);
}
}
else if(payment>=1000 && payment<=10000){
fee =(payment*1)/100.0f;
if(fee>15){
System.out.println("Amount of the fee that they owe (real number): $"+fee);
}else{
System.out.println("Amount of the fee that they owe (real number): $"+15);
}
} /* here we need to devide number into 10000 , $5000 and more
and need to apply charges 1%, 2%, 3% respectively*/
else if(payment>10000){
fee=0;
int feefor1st$10000; // apply charges 1%
int feeforNext$5000; // apply charges 2%
int remaining; // apply charges 3%
feeforNext$5000=payment-10000;
fee=fee+100; // for 1st 10000
if(feeforNext$5000>5000){
fee=fee+100; // next 5000
remaining=feeforNext$5000-5000;
fee=fee+(remaining*3)/100.0f; // calculating for remaining amount and adding it to fee
System.out.println("Amount of the fee that they owe (real number): $"+fee);
}
else {
fee=fee+(feeforNext$5000*2)/100.0f; // if less than $5000
System.out.println("Amount of the fee that they owe (real number): $"+fee);
}
}
}
}
****************** output*********************
Enter payment amount:
450
Amount you have entered: 450
Amount of the fee that they owe (real number): $13.5
---------------------
Enter payment amount:
40000
Amount you have entered: 40000
Amount of the fee that they owe (real number): $950.0
-------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.