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.
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!
Learn more about our help with Assignments:
JavaJSPJSF