Answer to Question #65448 in Java | JSP | JSF for gazibo

Question #65448
1. The following steps calculate the percentage profit from the sale of a stock. Convert the statements below to java code.

(a) Declare all variables as type Double.
(b) Ask user to input purchasePrice.
(c) Ask user to input sellingPrice.
(d) Assign, to the variable percentProfit, 100 times the value of the difference between sellingPrice and purchasePrice divided by purchasePrice.

Display the value of the variable percentProfit.
1
Expert's answer
2017-02-23T10:05:06-0500
import java.util.Scanner;

public class SaleOfStock {
static double purchasePrice;
static double sellingPrice;
static double percentProfit;

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please input purchasePrice: ");
purchasePrice = scanner.nextDouble();
System.out.println("Please input sellingPrice: ");
sellingPrice = scanner.nextDouble();
percentProfit = 100 * (sellingPrice - purchasePrice);
System.out.println("percentProfit is " + percentProfit + "%");
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS