0

Computing a fare meter using java (What is wrong with my codes?)

import java.util.Scanner; class Main{ public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print("Enter the distance travelled (meters): "); int dist = in.nextInt(); double fare = 2.50; if (dist <= 250) fare = 40; else if (dist <= 450) fare = 40 + 2.50; else if (dist <= 451) fare = 40 + 5; else if (dist <= 700) fare = 40 + 7.50; else if (dist <= 701) fare = 40 + 10; else if (dist <= 900) fare = 40 + 12.50; else if (dist <= 901) fare = 40 + 15; else fare = 40 + 15 + 2.50 ; System.out.println("Total cost = P"+fare+0); } }

24th Sep 2021, 7:49 AM
ruiririririri
ruiririririri - avatar
7 odpowiedzi
+ 5
Martin Taylor thank you for your feedback! I’ll try to edit my code and make it better. Have a nice day!
24th Sep 2021, 9:01 AM
ruiririririri
ruiririririri - avatar
+ 2
Atul [Inactive] this is a program that answers the following problem situation: The taxi has a base fee of 40.00 for the first 250 meters. An additional 2.50 is added for every succeeding 200 meters. Compute and print the total fare that you is needed to pay.
24th Sep 2021, 8:14 AM
ruiririririri
ruiririririri - avatar
+ 1
Nothing is wrong with your code please tell the expected output?
24th Sep 2021, 8:11 AM
Atul [Inactive]
+ 1
The expected output is Enter the distance travelled (meters): Total cost =
24th Sep 2021, 8:15 AM
ruiririririri
ruiririririri - avatar
0
dist=input("Enter the distance travelled (meters): ") print() base_fare=40.00 charge_per_meter=2.50 free_distance = 250 fare=0 succeeding_dist = 200 if (float)(dist) <= free_distance : fare = (float)(base_fare) else : calculate = (( ((float)(dist) - (float)(free_distance)) / succeeding_dist) * (float)(charge_per_meter)); fare = (float)(base_fare) + (float)(calculate) print("Total cost = P%0.2f" %(float)(fare)) ''' The taxi has a base fee of P40.00 for the first 250 meters. An additional P2.50 is added for every succeeding 200 meters. '''
8th Oct 2021, 12:39 AM
Jmar
Jmar - avatar
0
is there a C Language version of this code, because we have the same exact question.
20th Sep 2022, 2:07 PM
Francis Ezekiel Alapide
Francis Ezekiel Alapide - avatar