I can explain you the procedure for that problem in C++.
But if your question is to find out bug in your java program. Hope for someone else to help
Comparing both the programs ( Algorithms ) will let you know the mistake.
Look out the comments in program for explanation
Happy Coding
#include <iostream>
using namespace std;
int main()
{
int p;
float q;
cin>>p>>q; //Scan In Inputs
if(p%5!=0) //Check if p is a multiple of 5
cout<<q<<endl; //If not, Transition is not valid, And so just print q value
else if(p+0.5>q) //Check if there are enough funds. +0.5 for cutting charges
cout<<q<<endl; //Again if not print q;
else //So finally all conditions satisfied
{
q=q-p-0.5; //Deduce the amount
cout<<q<<endl; //Print q
}
return 0;
}
Please accept an answer (by clicking on the tick on the left side of the answer) if you think your question has been answered. If not, please comment on the answer requesting clarification.