I\'m stuck on a java programming question and was wondering if you could shed so
ID: 675509 • Letter: I
Question
I'm stuck on a java programming question and was wondering if you could shed some light on the subject.
Cindy uses the services of a brokerage firm to buy and sell stocks. The firm charges 1.5% service charges on the total amount for each transaction, buy or sell. When Cindy sells stocks, she would like to know if she gained or lost on a particular investment. Write a program that allows Cindy to input the number of shares sold, the purchase price of each share, and the selling price of each share. The program outputs the amount invested, the total service charges, amount gained or lost, and the amount received after selling the stock.
Explanation / Answer
import java.io.*;
import java.util.Scanner;
class SharePrice{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
double cp = in.nextDouble();
double sp = in.nextDouble();
int noP = in.nextInt();//number of purchased shares
int noS = in.nextInt();
double invested = cp*noP - sp*noS;
System.out.println("Amount invested:" + invested );
double serviceCharge = 0.015*(cp*noP+sp*noS);
System.out.println("Total service charges:" + serviceCharge);
double pl = sp*noS - cp*noP - serviceCharge;
System.out.println("Amount gained or lost:"+ pl);
System.out.println("Amount received after selling stock:"+ noS*sp - 0.015*noS*sp);
}
}