Advertisement
psi_mmobile

Advanced solution (true min)

Apr 18th, 2022
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. public class MyClass {
  2. public static void main(String args[]) {
  3. int minCabRange = 0;
  4. int minBusRange = 20;
  5. int minTrainRange = 100;
  6.  
  7. double baseCabTax = 0.70;
  8. double dayCabTaxPerKm = 0.79;
  9. double nightCabTaxPerKm = 0.90;
  10.  
  11. double busTaxPerKm = 0.09;
  12. double trainTaxPerKm = 0.06;
  13.  
  14. java.util.Scanner scanner = new java.util.Scanner(System.in);
  15. int kilometers = scanner.nextInt();
  16. String tariff = scanner.next();
  17.  
  18. double priceForCab = 0.0;
  19.  
  20. double priceForBus = 0.0;
  21.  
  22. double priceForTrain = 0.0;
  23.  
  24. if (tariff.equalsIgnoreCase("day")) {
  25. priceForCab = baseCabTax + kilometers * dayCabTaxPerKm;
  26. }
  27. if (tariff.equalsIgnoreCase("night")) {
  28. priceForCab = baseCabTax + kilometers * nightCabTaxPerKm;
  29. }
  30.  
  31. priceForBus = kilometers * busTaxPerKm;
  32.  
  33. priceForTrain = kilometers * trainTaxPerKm;
  34. double smallest = priceForCab;
  35. // >= 100km
  36. if (priceForTrain != 0 && kilometers > 100) {
  37. if(priceForTrain<priceForBus) {
  38. if(priceForCab<priceForTrain) {
  39. smallest = priceForCab;
  40. } else {
  41. smallest = priceForTrain;
  42. }
  43. } else {
  44. if(priceForBus<priceForCab) {
  45. smallest = priceForBus;
  46. } else {
  47. smallest = priceForCab;
  48. }
  49. }
  50. }
  51. // >= 20 && < 100
  52. if (priceForBus != 0 && (kilometers >= 20 && kilometers < 100)) {
  53. if (priceForCab > priceForBus) {
  54. smallest = priceForBus;
  55. }
  56. if (priceForCab < priceForBus) {
  57. smallest = priceForCab;
  58. }
  59. if (priceForBus == priceForCab) {
  60. smallest = priceForCab;
  61. }
  62. }
  63.  
  64. System.out.printf("%.2f",smallest);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement