Question
Write a java program (StockTransaction.java) that uses double linked lists to calculate capital gains of stocks. You are NOT allowed to use any of the
Write a java program (StockTransaction.java) that uses double linked lists to calculate capital gains of stocks. You are NOT allowed to use any of the Java Collections Framework classes such as Java ArrayList, LinkedList, HashMap, etc to implement this. You will read in two input text files stocks.txt and transactions.txt
Name your main program as StockTransaction.java
Sample Runs
Java StockTransaction
--successfully read stocks.txt and transactions.txt
Please enter a input stock quote for realized gain(or loss) for the stock : AAPL
Congratulations, your realized gain for Apple Inc. is : $150
Java StockTransaction
--successfully read stocks.txt and transactions.txt
Please enter a input stock quote for realized gain(or loss) for the stock : FB
Sorry, your realized loss for Facebook Inc. is : $500
Text Files
The stocks.txt file contains stock codes and descriptions in the following format:
AAPL;Apple Inc.
IBM; International Business Machines Corp.
KO; The Coca-Cola Company
FB; Facebook Inc.
SBUX;Starbucks Corp.
The transactions.txt file contains different transactions in chronological order a user conducts on shares. The format will be as follows
AAPL;buy;10;$450
KO;buy;100;$30
IBM;buy;50;$150
FB;buy;10;$30
AAPL;sell;5;$480
KO;sell;50;$50
FB;buy;30;$40
IBM;buy;50;$50
FB;sell;20;$10
SBUX;sell;30;$50
Implement the following codes
public class DList
protected DLLNode
protected DLLNode
protected int size;
public DList() {
header = null;
trailer = null;
size = 0;
}
/**
* @return the header
*/
public DLLNode
return header;
}
/**
* @return the trailer
*/
public DLLNode
return trailer;
}
/**
* @return the size
*/
public int getSize() {
return size;
}
// add element to the front of the list
public void addToFront(T elem) {
DLLNode
if (header == null) {
header = newNode;
}
if (trailer == null)
trailer = newNode;
else {
newNode.setLink(header);
header.setBack(newNode);
header = newNode;
}
size++;
}
// add element to the end of the list
public void addToLast(T elem) {
DLLNode
newNode.setLink(null);
if (trailer == null) {
trailer = newNode;
header = newNode;
} else {
trailer.setLink(newNode);
newNode.setBack(trailer);
trailer = newNode;
}
size++;
}
public boolean isEmpty() {
return header == null;
}
public String toString() {
DLLNode
String result = "";
while(node!= null) {
result+=node.getInfo();
result+="<=>";
node = (DLLNode
}
result = result.substring(0,result.length()-3);
return result;
}
public void print() {
DLLNode
while (v != null) {
System.out.println(v.getInfo());
v = (DLLNode) v.getLink();
}
}
//2) Define a recursive method, boolean search (T element) in DList
//class that returns true if the element is
// found in the double linked list.
public boolean search(T element) {
return search (header,element);
}
private boolean search(DLLNode
if(node == null)
return false;
if(node.getInfo().equals(element))
return true;
else
return search((DLLNode
}
//Given the DList class, implement a void removeLast() method
//which removes the last node in the double linked list
public void removeLast() {
if (isEmpty())
throw new IllegalStateException("cannot remove from empty DList");
DLLNode
u.setLink(null);
trailer = u;
}
// implement stack operations void push(T element) and T pop()
public void push(T element) {
DLLNode
addToLast(element);
}
public T pop() {
return null;
}
}
2
public class DLLNode
private DLLNode
public DLLNode(T info)
{
super(info);
back = null;
}
public void setBack(DLLNode
// Sets back link of this DLLNode.
{
this.back = back;
}
public DLLNode getBack()
// Returns back link of this DLLNode.
{
return back;
}
}
3
public class LLNode
private LLNode
private T info;
public LLNode(T info)
{
this.info = info;
link = null;
}
public void setInfo(T info)
// Sets info of this LLNode.
{
this.info = info;
}
public T getInfo()
// Returns info of this LLONode.
{
return info;
}
public void setLink(LLNode
// Sets link of this LLNode.
{
this.link = link;
}
public LLNode
// Returns link of this LLNode.
{
return link;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started