Computer Science, asked by jkpavithramalyaa, 1 year ago

write a java program to calculate of profit after reading cost price and selling price through keyboard.

Answers

Answered by BrainlyTech
35

\textbf{ \large{ Hello Friend! }}


\textbf{ How are you doing today? }


\textbf{ I'm here to help you with your answer.. }


\textbf{ Lets get started! }


\textbf{ Here is what I got for you! }

\textbf{ import java.util.Scanner;  }


\textbf{ public class Program  }

{


   \textbf{ public static void main( String[] args )  }

   {


       float SP, Profit, CP;


       Scanner reader = new Scanner(System.in);


       


       System.out.println("Enter Total Selling Price and Profit : ");


       SP = reader.nextFloat();


       Profit = reader.nextFloat();


       


       CP = SP - Profit;


       CP = CP / 15;


       


       System.out.println("\nCost Price per Item is : " + CP);


   }


}

\textbf{ \large{ Be Brainly! }}

Answered by Shivu516
2

Hope it helps ^_^

This is a dynamic program, it asks for the input from the user. It also calculates loss.

___________________________________

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