Companies and people often buy and sell stocks Often they bu

Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock (such as Checkpoint), one may have bought the stock in amounts of 100 shares over 10 different times with 10 different prices.

We will analyze two different methods of accounting, FIFO and LIFO accounting used for determining the “cost” of a stock. This is also known as the dollar cost average basis. This information is typically calculated when a stock is sold to determine if a profit or loss was made. In our version of FIFO accounting, the price of a commodity is averaged starting with the first purchase of that item. Say we sell 250 shares of a stock, according to this method the dollar cost averaged purchase price is determined by averaging the prices on the first 250 shares bought. In our version of LIFO accounting, the price of a commodity is averaged starting with the last purchase of that item. Say we sell 250 shares of a stock, according to this method the dollar cost average purchase price is determined by averaging the prices on the last 250 shares bought.

In this assignment, you will be using a queue for storing data for FIFO accounting, and a stack for LIFO accounting. Implement your queue using Link list and implement your stack using the stack class in java.util. Make sure you use the stack and queue abstract data types (ADT) defined for stacks and queues. Both your stack and queue should have records with the following fields:
The stock Ticker symbol (a string).

The stock Ticker symbol (a string).

The number of shares of a stock (an int

The purchase price for those shares (decimal).

You can assume that the first element of the structure is the security bought first, the second was bought second, etc.

Your program should have the user able to enter information about various stocks, the amount of shares, and the price. The user can then enter a query about a certain stock and the cost according to the LIFO and FIFO accounting methods for a certain number of shares.

The following could be your menu:
Press 1 to enter a new stock
Press 2 to find the LIFO and FIFO dollar cost average for the number of shares sold.

If 1 is pressed, the user needs to enter the stock symbol, Stock name, the number of shares bought, and the price per share when purchased.

If 2 is pressed, the user needs to enter the stock symbol being queried and the number of shares you wish to sell. Once that information is entered the dollar cost averaged price per share for both the LIFO method and the FIFO method should be displayed.

Implement the program described above using the Java programming language to meet the overall requirements described above. Use the blow data.

Ticker: XOM
Name:Exon Mobile
Purchases in the order below.

1. 100 shares at 92.65 2. 50 shares at 97.23 3. 200 shares at 84.50 4. 100 shares at 86.58

Ticker:D
Name:Dominion Resources Purchases in the order below.

1. 350 shares at64.98 2. 200 shares at 66.72 3. 100 shares at 69.00 4. 180 shares at 71.75

After you enter the XOM data have the software calculate and display the dollar cost average basis for both the LIFO and FIFO methods when selling 300 shares.

After you enter the D data have the software calculate and display the dollar cost average basis using both the LIFO and FIFO methods when selling 400 shares.





Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock (such as Checkpoint), one may have bought the stock in amounts of 100 shares over 10 different times with 10 different prices.

We will analyze two different methods of accounting, FIFO and LIFO accounting used for determining the “cost” of a stock. This is also known as the dollar cost average basis. This information is typically calculated when a stock is sold to determine if a profit or loss was made. In our version of FIFO accounting, the price of a commodity is averaged starting with the first purchase of that item. Say we sell 250 shares of a stock, according to this method the dollar cost averaged purchase price is determined by averaging the prices on the first 250 shares bought. In our version of LIFO accounting, the price of a commodity is averaged starting with the last purchase of that item. Say we sell 250 shares of a stock, according to this method the dollar cost average purchase price is determined by averaging the prices on the last 250 shares bought.

In this assignment, you will be using a queue for storing data for FIFO accounting, and a stack for LIFO accounting. Implement your queue using Link list and implement your stack using the stack class in java.util. Make sure you use the stack and queue abstract data types (ADT) defined for stacks and queues. Both your stack and queue should have records with the following fields:
The stock Ticker symbol (a string).

The stock Ticker symbol (a string).

The number of shares of a stock (an int

The purchase price for those shares (decimal).

You can assume that the first element of the structure is the security bought first, the second was bought second, etc.

Your program should have the user able to enter information about various stocks, the amount of shares, and the price. The user can then enter a query about a certain stock and the cost according to the LIFO and FIFO accounting methods for a certain number of shares.

The following could be your menu:
Press 1 to enter a new stock
Press 2 to find the LIFO and FIFO dollar cost average for the number of shares sold.

If 1 is pressed, the user needs to enter the stock symbol, Stock name, the number of shares bought, and the price per share when purchased.

If 2 is pressed, the user needs to enter the stock symbol being queried and the number of shares you wish to sell. Once that information is entered the dollar cost averaged price per share for both the LIFO method and the FIFO method should be displayed.

Implement the program described above using the Java programming language to meet the overall requirements described above. Use the blow data.

Ticker: XOM
Name:Exon Mobile
Purchases in the order below.

1. 100 shares at 92.65 2. 50 shares at 97.23 3. 200 shares at 84.50 4. 100 shares at 86.58

Ticker:D
Name:Dominion Resources Purchases in the order below.

1. 350 shares at64.98 2. 200 shares at 66.72 3. 100 shares at 69.00 4. 180 shares at 71.75

After you enter the XOM data have the software calculate and display the dollar cost average basis for both the LIFO and FIFO methods when selling 300 shares.

After you enter the D data have the software calculate and display the dollar cost average basis using both the LIFO and FIFO methods when selling 400 shares.






We will analyze two different methods of accounting, FIFO and LIFO accounting used for determining the “cost” of a stock. This is also known as the dollar cost average basis. This information is typically calculated when a stock is sold to determine if a profit or loss was made. In our version of FIFO accounting, the price of a commodity is averaged starting with the first purchase of that item. Say we sell 250 shares of a stock, according to this method the dollar cost averaged purchase price is determined by averaging the prices on the first 250 shares bought. In our version of LIFO accounting, the price of a commodity is averaged starting with the last purchase of that item. Say we sell 250 shares of a stock, according to this method the dollar cost average purchase price is determined by averaging the prices on the last 250 shares bought.

In this assignment, you will be using a queue for storing data for FIFO accounting, and a stack for LIFO accounting. Implement your queue using Link list and implement your stack using the stack class in java.util. Make sure you use the stack and queue abstract data types (ADT) defined for stacks and queues. Both your stack and queue should have records with the following fields:
The stock Ticker symbol (a string).

The stock Ticker symbol (a string).

The number of shares of a stock (an int

The purchase price for those shares (decimal).

You can assume that the first element of the structure is the security bought first, the second was bought second, etc.

Your program should have the user able to enter information about various stocks, the amount of shares, and the price. The user can then enter a query about a certain stock and the cost according to the LIFO and FIFO accounting methods for a certain number of shares.

The following could be your menu:
Press 1 to enter a new stock
Press 2 to find the LIFO and FIFO dollar cost average for the number of shares sold.
Press 1 to enter a new stock
Press 2 to find the LIFO and FIFO dollar cost average for the number of shares sold.

If 1 is pressed, the user needs to enter the stock symbol, Stock name, the number of shares bought, and the price per share when purchased.

If 2 is pressed, the user needs to enter the stock symbol being queried and the number of shares you wish to sell. Once that information is entered the dollar cost averaged price per share for both the LIFO method and the FIFO method should be displayed.

Implement the program described above using the Java programming language to meet the overall requirements described above. Use the blow data.

Ticker: XOM
Name:Exon Mobile
Purchases in the order below.
Ticker: XOM
Name:Exon Mobile
Purchases in the order below.

1. 100 shares at 92.65 2. 50 shares at 97.23 3. 200 shares at 84.50 4. 100 shares at 86.58

Ticker:D
Name:Dominion Resources Purchases in the order below.
Ticker:D
Name:Dominion Resources Purchases in the order below.

1. 350 shares at64.98 2. 200 shares at 66.72 3. 100 shares at 69.00 4. 180 shares at 71.75

After you enter the XOM data have the software calculate and display the dollar cost average basis for both the LIFO and FIFO methods when selling 300 shares.

After you enter the D data have the software calculate and display the dollar cost average basis using both the LIFO and FIFO methods when selling 400 shares.





Solution

Answer:

import java.util.*;

public class HelloWorld

{

       

        public static void main(String[] args)

          {

               

System.out.println(\"Program for stock trading!\");               

                System.out.println(\"Press 1 to enter a new stock\");

                System.out.println(\"Press 2 to find Avg vost by FIFO and LIFO.\");

                System.out.println(\"Press 3 to quit\");

               

                Stack<myTradeStk> st1 = new Stack<myTradeStk>();

                Queue<myTradeStk> qqe1 = new LinkedList<myTradeStk>();

                Scanner mScanr = new Scanner(System.in);

                while(true){

                        String ot1 = mScanr.nextLine();                        

                        switch(ot1)

              {

                                case \"1\":

       

                                        System.out.println(\"Enter stock symbol\");                                       

                                        String tkSym = mScanr.nextLine();

                        System.out.println(\"Enter stock Name\");                                       

                                        String ttkName = mScanr.nextLine();

                        System.out.println(\"Enter no of shares purchased:\");

                        int nShares=mScanr.nextInt();

                        System.out.println(\"Enter shares and prices:\");

                        int[] sharAry=new int[nShares];                     

                        float[] sharPric=new float[nShares];

                        for(int kk=0;kk<nShares;kk++)

                        {

                             sharAry[kk]=mScanr.nextInt();

                             sharPric[kk]=mScanr.nextFloat();  

                        }                                    

                        myTradeStk myNewStk=new myTradeStk(tkSym,ttkName, nShares, sharAry, sharPric);                        

                                      

                                        st1.push(myNewStk);

                                        qqe1.offer(myNewStk);

                                        break;

                               

                                case \"2\":

                                        System.out.println(\"Enter stock Name and no. of shares:\");

                                        String myTkName = mScanr.nextLine();

                        int nSha=mScanr.nextInt();                                  

                                        for(int kk=0;kk<st1.size();kk++)

                        {

                            

                             myTradeStk r1= st1.get(kk);

                             if(r1.getTkkNme().equals(myTkName))

                             {

System.out.println(\"Average cost-price by LIFO method:\" + r1. myStkLifoPrice(nSha));

                            

                                  System.out.println(\"Average cost-price by FIFO method:\" + r1. myStkFifoPrice(nSha));

                                  break;

                             }

                        }                             

                                        

       

                               

                       

                                case \"3\":                                       

                                        mScanr.close();

                                        System.exit(0);

                               

                        }

                }

       

        }

        static class myTradeStk

          {

               private String ttkName;

               private String tkSym;

               private int noShr;

               private int[] myShr1;

               private float[] myShrPrice;

               

myTradeStk(String symb, String tNme, int nshares1, int[] shares1, float[] price)

               {

                    tkSym=symb;                

                   ttkName=tNme;

                   noShr=nshares1;

                        myShr1 = new int[shares1.length];

                        myShrPrice=new float[price.length];

                        for(int kk=0;kk<shares1.length;kk++)

                        {

                             myShr1[kk]=shares1[kk];

                             myShrPrice[kk]=price[kk];

                        }

                       

                       

                }

          public String getTkkNme()

          {

              return ttkName;

          }

               

                                

                @Override

                public String toString()

               {

                        String myStk1=\"\";

              myStk1+=\"Ticker:\"+tkSym;

              myStk1+=\"\ Name:\"+ttkName;

              myStk1+=\"\ Purchases in the order below:\";

              for(int kk=0;kk<noShr;kk++)

              {

myStk1+=myShr1[kk]+\" shares at \"+ myShrPrice[kk];

              }

              return myStk1;

          }

          public float myStkLifoPrice(int saleSh)

          {

              float mylifCst=0;

              int tt=saleSh;

              for(int kk=0;kk<noShr;kk++)

              {

                  

                   if(saleSh>0)

                   {

                       

                        if(myShr1[kk]<saleSh)

                        {

mylifCst += myShr1[kk]*myShrPrice[kk];

                             saleSh=saleSh-myShr1[kk];

                            

                        }

                        else if(myShr1[kk]>saleSh)

                        {

                                 

mylifCst += saleSh*myShrPrice[kk];

                                  saleSh=0;

                        }

                   }

                  

              }

              float avgCost= mylifCst/tt;

              return avgCost;

          }

          public float myStkFifoPrice(int saleSh)

          {

              float myfifCst=0;

              int tt=saleSh;

              for(int kk=noShr-1;kk>=0;kk--)

              {

                   if(saleSh>0)

                   {

                        if(myShr1[kk]<saleSh)

                        {

myfifCst += myShr1[kk]*myShrPrice[kk];

                             saleSh=saleSh-myShr1[kk];

                        }

                        else if(myShr1[kk]>saleSh)

                        {

                                 

                                  myfifCst += saleSh*myShrPrice[kk];

                             saleSh=0;

                        }

                   }

             

              }

              float avgCost= myfifCst/tt;

               return avgCost;

          }

        }

}

Sample output:

sh-4.3$ javac HelloWorld.java                                                                                                     

sh-4.3$ java -Xmx128M -Xms16M HelloWorld

Program for stock trading!

Press 1 to enter a new stock

Press 2 to find Avg vost by FIFO and LIFO.

Press 3 to quit

1

Enter stock symbol

XON

Enter stock Name

EXION Mobiles

Enter no of shares purchased:

4

Enter shares and prices:

100

92.65

50

97.23

200

84.57

100

86.50

1

Enter stock symbol

D

Enter stock Name

Dominion Resources

Enter no of shares purchased:

4

Enter shares and prices:

350

64.98

200

66.72

100

69.00

180

69.90

2

Enter stock Name and no. of shares:

Dominion Resources

550

Average cost-price by LIFO method::66.60545

Average cost-price by FIFO method::67.95382

3

 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock
 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock
 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock
 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock
 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock
 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock
 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock
 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock
 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock
 Companies and people often buy and sell stocks. Often they buy the same stock for different prices at different times. Say one owns 1000 shares a certain stock

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site