Nackey

transport price - if else

Jul 18th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Transport {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.  
  7.         int km = Integer.parseInt(sc.nextLine());
  8.         String tarifa = sc.nextLine();
  9.  
  10.         double taxi =0;
  11.         double price =0;
  12.  
  13.         if (tarifa.equals("day")){
  14.             taxi = 0.79;
  15.         } else taxi = 0.90;
  16.  
  17.         if (km < 20) {
  18.             price = 0.70+(km * taxi);
  19.         } else if (km<100){
  20.             price = km*0.09;
  21.         } else {
  22.             price = km*0.06;
  23.         }
  24.         System.out.printf("%.2f", price);
  25.  
  26.  
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment