Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to alter this Java program to allow user input for amount of shares purch

ID: 3665857 • Letter: I

Question

I need to alter this Java program to allow user input for amount of shares purchased, cost of shares purchased, broker's commission, and amount sold for. Here is the code I have so far:

/**

* Chapter 2

* Programming Challenge 18: Stock Transaction Program

*/

public class StockTransactionProgram

{

   public static void main(String[] args)

   {

      // Named constants

      final int NUM_SHARES = 1000;          // Number of shares

      final double PURCHASE_PRICE = 32.87; // Purchase price per share

      final double SELLING_PRICE = 33.92;   // Selling price per share

      final double BROKER_COMM_RATE = 0.02; // Broker commission rate

     

      // Calculate the cost of the stock (without the

      // broker's commission) and store the result

      // in stockPurchase.

      double stockPurchase = (NUM_SHARES * PURCHASE_PRICE);

     

      // Calculate the broker's commission on the purchase and

      // store the result in purchaseComm.

      double purchaseComm = stockPurchase * BROKER_COMM_RATE;

     

      // Calculate the total amount Joe paid for the stock plus the

      // broker's commission and store the result in amountPaid.

      double amountPaid = stockPurchase + purchaseComm;

     

      // Calculate the amount Joe sold the stock for and store

      // the result in stockSale.

      double stockSale = NUM_SHARES * SELLING_PRICE;

     

      // Calculate the broker's commission on the sale and

      // store the result in sellingComm.

      double sellingComm = (NUM_SHARES * SELLING_PRICE) *

                           BROKER_COMM_RATE;

     

      // Calculate the amount that Joe actually recieved after

      // selling the stock and paying his broker the sales

      // commission, and store the result in amountRecieved.

      double amountRecieved = stockSale - sellingComm;

     

      // Calculate the amount of profit or loss, and store the

      // result in profitOrLoss. If a profit was made, the amount

      // will be positive. If a loss was incurred, the amount

      // will be negative.

      double profitOrLoss = amountRecieved - amountPaid;

     

      // Display the results.

      System.out.printf("Joe paid $%,.2f for the stock. ", stockPurchase);

      System.out.printf("Joe paid his broker a commission of $%,.2f on" +

                        " the purchase. ", purchaseComm);

      System.out.printf("So, Joe paid a total of $%,.2f ", amountPaid);

      System.out.printf(" Joe sold the stock for $%,.2f ", stockSale);

      System.out.printf("Joe paid his broker a commission of $%,.2f on" +

                        " the sale. ", sellingComm);

      System.out.printf("So, Joe recieved a total of $%,.2f ", amountRecieved);

     System.out.printf(" Joe's profit or loss: $%,.2f ", profitOrLoss);

   }

}

Please help,

Thanks

Explanation / Answer

No need to mention final int

int NUM_SHARES = 1000;

double PURCHASE_PRICE = 32.87;

double SELLING_PRICE = 33.92;

double BROKER_COMM_RATE = 0.02;

Give

System.out.println

Dont mention System.out.printf

It will give a wrong syntax

Give selling_price instead of sellingComm

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote