145 lines
9.6 KiB
HTML
145 lines
9.6 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Stock.java</title>
|
||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
|
||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
|
||
|
table {color: #888888; background-color: #313335; font-family: monospace}
|
||
|
.string {color: #6a8759}
|
||
|
.number {color: #6897bb}
|
||
|
.comment {color: #808080}
|
||
|
.whitespace {color: #505050}
|
||
|
.ST0 {color: #808080; font-family: monospace; font-weight: bold}
|
||
|
.literal {color: #cc7832}
|
||
|
-->
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/Stock.java</td></tr></table>
|
||
|
<pre>
|
||
|
<span class="comment">/*</span>
|
||
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||
|
<span class="comment"> */</span>
|
||
|
<span class="literal">package</span> com.calebfontenot.lab3_calebfontenot;
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">class</span> Stock {
|
||
|
|
||
|
<span class="literal">private</span> String symbol;
|
||
|
<span class="literal">private</span> String name;
|
||
|
<span class="literal">private</span> <span class="literal">double</span> previousClosingPrice;
|
||
|
<span class="literal">private</span> <span class="literal">double</span> currentPrice;
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">currentPrice</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST0">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">currentPrice</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">double</span> getCurrentPrice()
|
||
|
{
|
||
|
<span class="literal">return</span> currentPrice;
|
||
|
}
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">currentPrice</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST0">@param</span> <span class="comment">currentPrice</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">currentPrice</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setCurrentPrice(<span class="literal">double</span> currentPrice)
|
||
|
{
|
||
|
<span class="literal">this</span>.currentPrice = currentPrice;
|
||
|
}
|
||
|
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">previousClosingPrice</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST0">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">previousClosingPrice</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">double</span> getPreviousClosingPrice()
|
||
|
{
|
||
|
<span class="literal">return</span> previousClosingPrice;
|
||
|
}
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">previousClosingPrice</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST0">@param</span> <span class="comment">previousClosingPrice</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">previousClosingPrice</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setPreviousClosingPrice(<span class="literal">double</span> previousClosingPrice)
|
||
|
{
|
||
|
<span class="literal">this</span>.previousClosingPrice = previousClosingPrice;
|
||
|
}
|
||
|
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">name</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST0">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">name</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> String getName()
|
||
|
{
|
||
|
<span class="literal">return</span> name;
|
||
|
}
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">name</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST0">@param</span> <span class="comment">name</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">name</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setName(String name)
|
||
|
{
|
||
|
<span class="literal">this</span>.name = name;
|
||
|
}
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">symbol</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST0">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">symbol</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> String getSymbol()
|
||
|
{
|
||
|
<span class="literal">return</span> symbol;
|
||
|
}
|
||
|
|
||
|
<span class="comment">/**</span>
|
||
|
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">symbol</span>
|
||
|
<span class="comment"> *</span>
|
||
|
<span class="comment"> * </span><span class="ST0">@param</span> <span class="comment">symbol</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">symbol</span>
|
||
|
<span class="comment">*/</span>
|
||
|
<span class="literal">public</span> <span class="literal">void</span> setSymbol(String symbol)
|
||
|
{
|
||
|
<span class="literal">this</span>.symbol = symbol;
|
||
|
}
|
||
|
|
||
|
<span class="literal">public</span> <span class="literal">double</span> getChangePercent() {
|
||
|
<span class="literal">return</span> <span class="literal">this</span>.currentPrice - <span class="literal">this</span>.previousClosingPrice;
|
||
|
<span class="comment">//(((this.previousClosingPrice - this.currentPrice) / Math.abs(this.previousClosingPrice)) * 100)</span>
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
<span class="literal">public</span> String toString()
|
||
|
{
|
||
|
<span class="literal">return</span> <span class="string">"</span><span class="string">Stock{</span><span class="string">"</span> + <span class="string">"</span><span class="string">symbol=</span><span class="string">"</span> + symbol + <span class="string">"</span><span class="string">, name=</span><span class="string">"</span> + name + <span class="string">"</span><span class="string">, previousClosingPrice=</span><span class="string">"</span> + previousClosingPrice + <span class="string">"</span><span class="string">, currentPrice=</span><span class="string">"</span> + currentPrice + <span class="string">"</span><span class="string">}</span><span class="string">"</span>+ <span class="string">"</span><span class="literal">\n</span><span class="string">"</span> + <span class="string">"</span><span class="string">Change in Percent: </span><span class="string">"</span> + <span class="literal">this</span>.getChangePercent();
|
||
|
}
|
||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
|
||
|
{
|
||
|
Stock stock1 = <span class="literal">new</span> Stock();
|
||
|
stock1.setSymbol(<span class="string">"</span><span class="string">ORCL</span><span class="string">"</span>);
|
||
|
stock1.setName(<span class="string">"</span><span class="string">Oracle Corporation</span><span class="string">"</span>);
|
||
|
stock1.setPreviousClosingPrice(<span class="number">34.5</span>);
|
||
|
stock1.setCurrentPrice(<span class="number">34.35</span>);
|
||
|
System.out.println(stock1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
</pre></body>
|
||
|
</html>
|