Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * @author Ravinesh
- *
- */
- public class que5_prolo {
- /**
- * @param args
- */
- static double costPrice, sellingPrice, rate, profitt, loss;
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner in = new Scanner(System.in);
- System.out.println("Enter : profit or loss");
- String choice = in.nextLine();
- System.out.println("Enter the Cost Price: ");
- costPrice = in.nextDouble();
- System.out.println("Enter the Rate: ");
- rate = in.nextDouble();
- if (choice.equals("profit")) {
- System.out.println("Profit % : " + pro(costPrice,rate));
- } else if (choice.equals("loss")) {
- System.out.println("Loss % : " + loss(costPrice,rate));
- }
- }
- public static double pro (double costPrice, double rate) {
- double amount = costPrice * (rate / 100);
- sellingPrice = costPrice + amount;
- profitt = ((sellingPrice / costPrice) -1) * 100 ;
- return profitt;
- }
- public static double loss (double costPrice, double rate) {
- double amount = costPrice * (rate / 100) ;
- sellingPrice = costPrice + amount;
- loss = ((costPrice / sellingPrice) -1) * 100 ;
- return loss;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment