Computer Science, asked by unknown1307, 2 months ago

Write a Java program to accept cost and selling price of any product and print profit or

loss amount or no profit and no loss.​

Answers

Answered by nisthainn
0

Answer:

Explanation:

Profit and loss is a concept which is not exclusive to business owners but it is something that everyone is ought to know to be financially wise. Want to sell an old merchandise at an online selling portal like Craigslist or Olx? Or even selling your unused guitar that you bought last summer, to a friend of yours? You ought to learn “Profit and Loss” buddy!

As you might already know, every transaction has a cost price, a selling price, or a profit or loss depending on the transaction.  If the cost price is more than the selling price, then the transaction is bound to be a loss and vice versa.

Here are the basic concepts of Profit and Loss

Cost price – The amount incurred to us while manufacturing or buying that commodity.

Selling price – The amount of money received after selling a given commodity.

Profit – The amount one gains in transaction when the selling price is greater than the cost price.

Loss – The amount one loses in a transaction when the cost price was greater than the selling price.

Answered by Shivu516
0

Hope it helps ^_^

Please mark my answer as Brainiest if you ever read this answer

import java.util.Scanner;

public class Profit_And_Loss_Calculator{

   public static void main(String [] args){

       Scanner sc = new Scanner(System.in);

       double cp, sp, gain, loss;

       //Taking input

       System.out.print("Enter the Cost Price: ");

       cp = sc.nextDouble();

       System.out.print("Enter the Selling Price: ");

       sp = sc.nextDouble();

       //Main part comes here

       if (cp > sp && cp >= 0 && sp >= 0){

           loss = cp - sp;

           double Loss_Percentage = (loss/cp) * 100;

           System.out.println("Loss: " + loss);

           System.out.println("Loss(%): " + Loss_Percentage);

       }

       else if (cp < sp && cp >= 0 && sp >= 0){

           gain = sp - cp;

           double Gain_Percentage = (gain/cp) * 100;

           System.out.println("Gain: " + gain);

           System.out.println("Gain(%): " + Gain_Percentage);

       }

       else if (cp == sp && cp >= 0 && sp >= 0){

           System.out.println("There is no Gain or Loss");

       }

       else if (cp < 0 || sp < 0){

           System.out.println("Invalid Input *_*");

       }

   }

}

The underlined values are the inputs

Output:

(i)

Enter the Cost Price: 50

Enter the Selling Price: 40

Loss: 10.0

Loss(%): 20.0

(ii)

Enter the Cost Price: 40

Enter the Selling Price: 50

Gain: 10.0

Gain(%): 25.0

(iii)

Enter the Cost Price: 90

Enter the Selling Price: 90

There is no Gain or Loss

(iv)

Enter the Cost Price: -50

Enter the Selling Price: -40

Invalid Input *_*

Thanks for reading till here ˶ᵔ ᵕ ᵔ˶

Attachments:
Similar questions