Using scanner class method
it is a java program
Please answer it correctly
I will mark you as brainlist
Please answer it very fast
Answers
CODE :
import java.util.*;
class Prepaid_taxi
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the distance travelled");
int d=sc.nextInt();
System.out.println("Enter the TAXI number");
int n=sc.nextInt();
int c=0;
if(d<=5)
{
c=d*100;
}
else if(d>5&&d<=15)
{
c=(5*100)+(15-d)*10;
}
else if(d>15&&d<=25)
{
c=(5*100)+(10*10)+(25-d)*8;
}
else
{
c=(5*100)+(10*10)+(10*8)+(d-25)*5;
}
System.out.println("Taxi No: "+n);
System.out.println("Distance travelled : "+d);
System.out.println("Charges :"+c);
}
}
IMPORTANT THINGS TO NOTE :
➡ When the distance travelled is upto 5 , then the money will be ( distance × 100 ).
➡ If distance is more than 5 , the money will be the previous charge of ( 100 × 5 ) and the remaining distance that is (15-d )× 10.
➡ The more the distance , the previous charges get added up.
➡ This kind of programs are called Dependence Slabs .
EXAMPLE :
Distance = 30
Charge = ( 5×100 ) + ( 10×10 ) + ( 10×8 ) + (d-25)×5
= > 500 + 100 + 80 + ( 30 - 25 )×5
= > 680 + 5×5
= > 680 + 25
= > 705
Thanks for the question !
__________________________________________________________________