Advertisement
ismail5g

Question-2

Apr 13th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1.  
  2. package assingment;
  3. import java.util.Scanner;
  4. class uber{
  5.     double TravelDistance;
  6.     double PerkmPrice;
  7.     int Promotion;
  8.     uber(double a, double b, int c){
  9.         TravelDistance=a;
  10.         PerkmPrice=b;
  11.         Promotion=c;
  12.     }
  13.     void Fare(){
  14.         double cost;
  15.         if(Promotion==1){
  16.             cost=(TravelDistance * PerkmPrice)-(((TravelDistance * PerkmPrice)*10)/100);
  17.            System.out.println("Total Cost : "+cost);
  18.         }else{            
  19.             cost=TravelDistance * PerkmPrice;
  20.             System.out.println("Total Cost : "+cost);
  21.         }
  22.     }
  23. }
  24.  
  25. class Main{
  26.     public static void main(String[] args){
  27.         Scanner input= new Scanner(System.in);
  28.         System.out.println("Enter Travel Distance in KM: ");
  29.         double distance = input.nextDouble();
  30.         System.out.println("Enter Price per KM: ");
  31.         double price = input.nextDouble();
  32.         System.out.println("Promotion Discount Active or Not press 1 or 0: ");
  33.         int PActive= input.nextInt();
  34.         uber use = new uber(distance, price, PActive);
  35.         use.Fare();
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement