gulzaar

profit loss

Feb 28th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. /**
  4.  * @author Ravinesh
  5.  *
  6.  */
  7. public class que5_prolo {
  8.  
  9.     /**
  10.      * @param args
  11.      */
  12.    
  13.     static double costPrice, sellingPrice, rate, profitt, loss;
  14.    
  15.        
  16.    
  17.     public static void main(String[] args) {
  18.         // TODO Auto-generated method stub
  19.        
  20.         Scanner in = new Scanner(System.in);
  21.        
  22.         System.out.println("Enter : profit or loss");
  23.         String choice = in.nextLine();
  24.        
  25.         System.out.println("Enter the Cost Price: ");
  26.         costPrice = in.nextDouble();
  27.        
  28.         System.out.println("Enter the Rate: ");
  29.         rate = in.nextDouble();
  30.            
  31.        
  32.         if (choice.equals("profit")) {
  33.             System.out.println("Profit % : " + pro(costPrice,rate));
  34.         } else if (choice.equals("loss")) {
  35.             System.out.println("Loss % : " + loss(costPrice,rate));
  36.         }
  37.        
  38.     }
  39.    
  40.    
  41.     public static double pro (double costPrice, double rate) {
  42.        
  43.         double amount =  costPrice * (rate / 100);
  44.        
  45.         sellingPrice = costPrice + amount;
  46.        
  47.         profitt = ((sellingPrice / costPrice) -1) * 100 ;
  48.        
  49.         return profitt;
  50.     }
  51.    
  52.     public static double loss (double costPrice, double rate) {
  53.        
  54.         double amount =  costPrice * (rate / 100) ;
  55.        
  56.         sellingPrice = costPrice + amount;
  57.        
  58.         loss = ((costPrice  / sellingPrice) -1) * 100 ;
  59.        
  60.         return loss;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment