Computer Science, asked by maddy623, 7 months ago

`write a java program (bluej) to input cost price and selling price of an article and find weather the user has made a profit or loss, also calculate and display the profit % or loss % based on the condition

Answers

Answered by swaroopa26
1

Answer:

Explanation:// Java Program to Calculate Profit or Loss

import java.util.Scanner;

public class ProfitorLoss {

private static Scanner sc;

public static void main(String[] args)  

{

 float saleAmount, unitPrice, amount;

 sc = new Scanner(System.in);

 

 System.out.print(" Please Enter the Actual Product Cost : ");

 unitPrice = sc.nextFloat();  

 

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

 saleAmount = sc.nextFloat();

 

 if(saleAmount > unitPrice )

 {

  amount = saleAmount - unitPrice;

  System.out.println("\n Profit Amount =  " + amount);

 }

 else if(unitPrice > saleAmount)

 {

  amount = unitPrice - saleAmount;

  System.out.println("\n Loss Amount =  " + amount);

 }

 else

 {

  System.out.println("\n No Profit No Loss! ");

 }

}

}

Answered by Shivu516
1

Hope it helps ^_^

___________________________________

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