Write a program that calculates the value of a stock sale. The user will be prom
ID: 3628419 • Letter: W
Question
Write a program that calculates the value of a stock sale. The user will be prompted to enter the stock price, the number of shares to be sold, and the commission rate. The program will calculate the value of the shares by multiplying the stock price by the number of shares. It will also calculate the commission (the value of the shares multiplied by the commission rate) and the net proceeds (the value of the shares minus the commission). The following example shows what the user will see on the screen:
This program calculates the net proceeds from a sale of stock.
Enter stock price: 10.125
Enter number of shares: 11
Value of shares: $111.38
Enter commission rate (as a percentage): 1.5
Commission: $1.67
Net proceeds: $109.71
The stock price, number of shares, and commission may contain digits after the decimal point. Dollar amounts must be rounded to the nearest cent.
Explanation / Answer
please rate - thanks
if JAVA is wrong, message me
import java.util.*;
public class main
{public static void main(String args[])
{Scanner in=new Scanner(System.in);
double price,rate,value,comm,net;
int shares;
System.out.print("Enter stock price: ");
price=in.nextDouble();
System.out.print("Enter number of shares: ");
shares=in.nextInt();
value=price*shares;
value=Math.round(value*100);
value/=100;
System.out.println("Value of shares: $"+value);
System.out.print("Enter commission rate (as a percentage): ");
rate=in.nextDouble();
comm=value*(rate/100.);
comm=Math.round(comm*100);
comm/=100;
System.out.println("Commission: $"+comm);
net=value-comm;
net=Math.round(net*100);
net/=100;
System.out.println("Net proceeds: $"+net);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.