Question

Write an application that queries the user for the following information about a stock transaction and...

Write an application that queries the user for the following information about a stock transaction and then displays the net gain or loss on the transaction.

  1. Number of shares bought and sold (this is one number not two)
  2. Purchase price per share
  3. Purchase commission as a double (for example, 2% commission would be 0.02)
  4. Sale price per share
  5. Sale commission as a double (for example, 2% commission would be 0.02)

You must allow the user to enter the values. However you can use the following numbers to check your lab

Shares = 1000

Purchase price = $45.2

Purchase commission = 2% or 0.02

Sale price = $46.5

Sale commission = 2% or 0.02

Net loss of $534

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Stock {
   public static void main(String[] args) {
       int sharesOfStock;
       double salePrice;
       double pricePerShare;
       double commissionRate;
       double saleCommision;
       double purchaseTotal = 0;
       double sellingTotal = 0;
       double total;
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter number of shares: ");
       sharesOfStock = sc.nextInt();
       System.out.println("Enter purchase price : ");
       pricePerShare = sc.nextDouble();
       System.out.println("Enter purchase commission : ");
       commissionRate = sc.nextDouble();
       commissionRate = commissionRate / 100;
       System.out.println("Enter sales price");
       salePrice = sc.nextDouble();
       System.out.println("Enter sale commission");
       saleCommision = sc.nextDouble();
       saleCommision = saleCommision / 100;
       // finding the amount paid only to the stock
       double totolStock = (sharesOfStock * pricePerShare);
       // finding the commission
       double commission = totolStock * commissionRate;
       // finding purchase total
       purchaseTotal = totolStock + commission;
       //finding selling price
       sellingTotal = sharesOfStock * salePrice;
       //finding selling price after commission
       sellingTotal = sellingTotal - (sellingTotal * saleCommision);
       //finding profits and losses
       total = sellingTotal - purchaseTotal;
       // if total is negative than it is loss
       System.out.println("Shares = "+sharesOfStock);
       System.out.println("Purchase price = "+pricePerShare);
       System.out.println("Purchase commission = "+(commission*100));
       System.out.println("Sale price= "+salePrice);
       System.out.println("Sale commission= "+(saleCommision*100));
      
      
       if (total < 0) {
          
           total=total*-1;
           System.out.println("Net loss $" + total);
       } else {
           System.out.println("Net profit $" + total);
       }
   }
}

Note : If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Write an application that queries the user for the following information about a stock transaction and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write an application that queries the user for the following information about a stock transaction and...

    Write an application that queries the user for the following information about a stock transaction and then displays the net gain or loss on the transaction. 1. Number of shares bought and sold (this is one number not two) 2. Purchase price per share 3. Purchase commission as a double (for example, 2% commission would be 0.02) 4. Sale price per share 5. Sale commission as a double (for example, 2% commission would be 0.02) You must allow the user...

  • Problem Statement Last month Tian purchased some stock in Acme Software, Inc. Here are the details...

    Problem Statement Last month Tian purchased some stock in Acme Software, Inc. Here are the details of the purchase:  The number of shares that Tian purchased was 1,000  When Tian purchased the stock, he paid $33.92 per share  Tian paid his stockbroker a commission that amounted to 2% of the amount he paid for the stock. One week later, Tian sold the stock. Here are the details of the sale: The number of shares sold was 1,000...

  • (PYTHON) Stock Transaction Program Last month Joe purchased some stock from StockTrade.   1. Write a function(s)...

    (PYTHON) Stock Transaction Program Last month Joe purchased some stock from StockTrade.   1. Write a function(s) to allow the user to input the followings: ·The name of the stock ·Number of shares Joe bought · Stock purchase price · Stock selling price ·Broker commission 2. Write function(s) to calculate: and: · The amount of money Joe paid for the stock (number of shares bought * purchase price) · The amount of commission Joe paid his broker when he bought the...

  • With a partner, use the problem solving approach covered on day 1. Write out an algorithm...

    With a partner, use the problem solving approach covered on day 1. Write out an algorithm on paper along with hand calculations to determine expected output. Add onto the algorithm from Problem Solving Challenge 1. Kathryn bought 750 shares of Microsoft Corporation (MSFT) stock at a price of $70.43 per share. She must pay her stock broker a 2% commission for the transaction. The algorithm should calculate and display the following: 1. The number of shares and stock symbol. 2....

  • 10. Stock Transaction Program 18pts Last month Joe purchased some stock in Acme Software, Inc. Here...

    10. Stock Transaction Program 18pts Last month Joe purchased some stock in Acme Software, Inc. Here are the details of the purchase: • The number of shares that Joe purchased was 1,000. • When Joe purchased the stock, he paid $32.87 per share. • Joe paid his stockbroker a commission that amounted to 2 percent of the amount he paid for the stock. Two weeks later Joe sold the stock. Here are the details of the sale: • The number...

  • Instructions Write a program called stocks.cpp. The program should prompt the user for the number of...

    Instructions Write a program called stocks.cpp. The program should prompt the user for the number of shares purchased, purchase price per share, the commission for the purchase, sale commission paid, and the price the shares were sold at. The program should validate each of these values to ensure they are acceptable (none of these values can be less than zero) and should then pass them to a function called calculateProfit. The function should use the following formula to determine the...

  • Please use C++ only CSIT163 Project 1 - Taking Stock Recently, Joe Btfsplk purchased some stock...

    Please use C++ only CSIT163 Project 1 - Taking Stock Recently, Joe Btfsplk purchased some stock in Acme Software, Inc. The details of the purchase are as follows: • 1,000 shares at $32.87 per share. • The stockbroker received $5 dollars plus a commission of 2% of the total purchase. Should he decide to sell, the stockbroker receives $5 dollars plus a commission of 2% of the total sale. Feeling jittery, Joe is considering selling the stock. The only thing...

  • C++ (i) Write a program that displays the following pattern: * *** ***** ******* ***** ***...

    C++ (i) Write a program that displays the following pattern: * *** ***** ******* ***** ***    * (ii) Katy bought 750 shares of stock at a price of $35.00 per share. She must pay her stockbroker a 2 percent commission for the transaction. Write a program that calculates and displays the following: The amount paid for the stock alone (without the commission) The amount of the commission) The total amount paid (stock plus commission) (iii) Write a program that...

  • ! Required information [The following information applies to the questions displayed below.) John bought 1,600 shares...

    ! Required information [The following information applies to the questions displayed below.) John bought 1,600 shares of Intel stock on October 18, 2015, for $42 per share plus a $750 commission he paid to his broker. On December 12, 2019, he sells the shares for $60.50 per share. He also incurs a $1,000 fee for this transaction. a. What is John's adjusted basis in the 1,600 shares of Intel stock? Adjusted basis Required information [The following information applies to the...

  • Required information (The following information applies to the questions displayed below.) John bought 2,050 shares of...

    Required information (The following information applies to the questions displayed below.) John bought 2,050 shares of Intel stock on October 18, 2015, for $51 per share plus a $750 commission he paid to his broker. On December 12, 2019, he sells the shares for $74.00 per share. He also incurs a $1,000 fee for this transaction. a. What is John's adjusted basis in the 2,050 shares of Intel stock? Adjusted basis Required information The following information applies to the questions...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT