Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass {
- public static void main(String args[]) {
- int minCabRange = 0;
- int minBusRange = 20;
- int minTrainRange = 100;
- double baseCabTax = 0.70;
- double dayCabTaxPerKm = 0.79;
- double nightCabTaxPerKm = 0.90;
- double busTaxPerKm = 0.09;
- double trainTaxPerKm = 0.06;
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- int kilometers = scanner.nextInt();
- String tariff = scanner.next();
- double priceForCab = 0.0;
- double priceForBus = 0.0;
- double priceForTrain = 0.0;
- if (tariff.equalsIgnoreCase("day")) {
- priceForCab = baseCabTax + kilometers * dayCabTaxPerKm;
- }
- if (tariff.equalsIgnoreCase("night")) {
- priceForCab = baseCabTax + kilometers * nightCabTaxPerKm;
- }
- priceForBus = kilometers * busTaxPerKm;
- priceForTrain = kilometers * trainTaxPerKm;
- double smallest = priceForCab;
- // >= 100km
- if (priceForTrain != 0 && kilometers > 100) {
- if(priceForTrain<priceForBus) {
- if(priceForCab<priceForTrain) {
- smallest = priceForCab;
- } else {
- smallest = priceForTrain;
- }
- } else {
- if(priceForBus<priceForCab) {
- smallest = priceForBus;
- } else {
- smallest = priceForCab;
- }
- }
- }
- // >= 20 && < 100
- if (priceForBus != 0 && (kilometers >= 20 && kilometers < 100)) {
- if (priceForCab > priceForBus) {
- smallest = priceForBus;
- }
- if (priceForCab < priceForBus) {
- smallest = priceForCab;
- }
- if (priceForBus == priceForCab) {
- smallest = priceForCab;
- }
- }
- System.out.printf("%.2f",smallest);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement