Starting from:
$29.99

$23.99

Stock Transaction Simulator Solution

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

He sold the stock for $36.78 per share

 

He paid his stockbroker another commission that amounted to 2% of the amount he received for the stock.

 

Please write a program that displays the following information:

 

·         The amount of money Tian paid for the stock.

 

·         The amount of commission Tian paid his broker when he bought the stock.

·         The amount that Tian sold the stock for.

·         The amount of commission Tian paid his broker when he sold the stock

 

·         Display the amount of profit that Tian made after selling his stock and paying the two commissions to his broker (If the amount of profit that your program displays is a negative number , then Tian lost money on the transaction)

 

 

Input

 

This program requires that you read in the following data values:

Ø   Number of shares to buy (an integer)

 

Ø   Price to be bought (a real number)

Ø  Number of shares to sell (an integer)

 

Ø   Price to be sold (an integer)

 

You will use entirely interactive I/O in this program, that is, all input is typed in at the keyboard by the user (person running the program), and all output goes to the console window.

 

 

Test case output: (green texts are user input)

 

Please enter your name: Tian

The number of shares you want to purchase: 1000

Purchase price: 33.92

 

The number of shares you want to sell: 1000

Sold price: 36.78

 

Tian has purchased 1000 at $33.92 and then sold 1000 at $36.78. He paid $678.4 for broker fee when buying the stock and $735.6 for broker fee when selling the stock. So his profit is $1446.0 Good bye

 

 

 

Miscellaneous

 

Be sure to read and understand the sections in the Course Syllabus handout on general project requirements. Also be sure to study the style, documentation and formatting guidelines discussed in the Programming Style Guidelines handout and in the lecture.

 

What file to submit on Blackboard

 

You must turn in your Java program source file which must be named as follows:

StockTransactionSimulator.java.

More products