Advertisement
mswi12

TransportPrice

Aug 29th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.     public class TransportPrice {
  4.     public static void main(String []args){
  5.         Scanner scanner = new Scanner(System.in);
  6.             int distance = Integer.parseInt(scanner.nextLine());
  7.             String dayOrNight = scanner.nextLine();
  8.             Double price = 0.0;
  9.            
  10.             if (distance >= 100) {
  11.                 price = 0.06 * distance;  //travel with train
  12.                 } else if (distance >= 20 && distance < 100) {
  13.                     price = 0.09 * distance; //travel with bus
  14.                 }
  15.                    
  16.                    
  17.             if (distance < 20 ){ // travel with taxi
  18.                 if (dayOrNight.equals("day")){
  19.                     price = (distance * 0.79) + 0.70; // day rate
  20.                 } else if (dayOrNight.equals("night")){
  21.                     price = (distance * 0.90) + 0.70; // night rate
  22.                 }
  23.                
  24.              }  
  25.    
  26.                
  27.         System.out.printf("%.2f", price);      
  28.                
  29.    
  30.      }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement