SlideShare a Scribd company logo
1 of 11
Download to read offline
import java.util.Random;
//defines the Stock class
public class Stock {
private String symbol;
private String name;
private double nextPrice;
private double currentPrice;
private double priceChange;
private double priceChangePercentage;
public Stock(String s, String n, double CP, double NP) {
symbol = s;
name = n;
nextPrice = NP;
currentPrice = CP;
}
public Stock() {
name = "Microsoft";
symbol = "MSFT";
nextPrice = 46.87;
currentPrice = 46.87;
}
public void setNextPrice(double nextPrice) {
if (nextPrice > 0)
this.nextPrice = nextPrice;
else
this.nextPrice = 0;
}
public void setCurrentPrice(double cPrice) {
if (currentPrice > 0) {
currentPrice = cPrice;
} else {
currentPrice = 0;
}
}
public double getCurrentPrice() {
return currentPrice;
}
public String getName() {
return name;
}
public void setName(String n) {
name = n;
}
public double getNextPrice() {
Random rand = new Random();
nextPrice = rand.nextDouble();
return nextPrice;
}
public String getSymbol() {
return symbol;
}
public void setSymbol(String s) {
symbol = s;
}
public double getChange() {
// formula : (current - next) / next * 100
priceChange = (currentPrice - nextPrice) / nextPrice * 100;
return priceChange;
}
public double SimulatePrice() {
Random rand = new Random();
priceChangePercentage = rand.nextInt(10) + 1;
if (priceChangePercentage % 2 == 0)
currentPrice += (currentPrice * (priceChangePercentage / 100.0));
else
currentPrice -= (currentPrice * (priceChangePercentage / 100.0));
return priceChangePercentage;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Stock [getCurrentPrice()=" + getCurrentPrice() + ", getName()="
+ getName() + ", getNextPrice()=" + getNextPrice()
+ ", getSymbol()=" + getSymbol() + ", getChange()="
+ getChange() + "]";
}
}
import java.util.Scanner;
public class StockPriceSimulator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String symbol;
String name;
double nextPrice;
double currentPrice;
System.out.print("Please enter the name of the stock:");
name = input.nextLine();
System.out.print("Please enter the symbol of the stock: ");
symbol = input.nextLine();
System.out.print("Please enter Current price of " + name + ":");
currentPrice = input.nextDouble();
System.out.print("Please enter next price of " + name + ":");
nextPrice = input.nextDouble();
Stock stock;
if (name.equals("NONE") || symbol.equals("NA") || currentPrice == 0.0
|| nextPrice == 0.0)
stock = new Stock();
else
stock = new Stock(symbol, name, currentPrice, nextPrice);
for (int i = 0; i < 30; i++) {
stock.SimulatePrice();
System.out.println(stock);
}
input.close();
}
}
OUTPUT:
Please enter the name of the stock:NONE
Please enter the symbol of the stock: DD
Please enter Current price of NONE:99
Please enter next price of NONE:98
Stock [getCurrentPrice()=51.556999999999995, getName()=Microsoft,
getNextPrice()=0.22684389480238243, getSymbol()=MSFT,
getChange()=22627.964552413654]
Stock [getCurrentPrice()=52.588139999999996, getName()=Microsoft,
getNextPrice()=0.8209357260355085, getSymbol()=MSFT, getChange()=6305.877869874233]
Stock [getCurrentPrice()=49.958732999999995, getName()=Microsoft,
getNextPrice()=0.36265111054409815, getSymbol()=MSFT,
getChange()=13675.976840397692]
Stock [getCurrentPrice()=53.95543163999999, getName()=Microsoft,
getNextPrice()=0.9724883297228907, getSymbol()=MSFT, getChange()=5448.182943786535]
Stock [getCurrentPrice()=49.0994427924, getName()=Microsoft,
getNextPrice()=0.43696372926786653, getSymbol()=MSFT,
getChange()=11136.503055909514]
Stock [getCurrentPrice()=51.063420504096, getName()=Microsoft,
getNextPrice()=0.11437740167806576, getSymbol()=MSFT, getChange()=44544.67609416631]
Stock [getCurrentPrice()=46.467712658727365, getName()=Microsoft,
getNextPrice()=0.08938738995292295, getSymbol()=MSFT, getChange()=51884.63976093294]
Stock [getCurrentPrice()=44.144327025791, getName()=Microsoft,
getNextPrice()=0.5339893602734628, getSymbol()=MSFT, getChange()=8166.892621827545]
Stock [getCurrentPrice()=46.79298664733846, getName()=Microsoft,
getNextPrice()=0.47925834918788124, getSymbol()=MSFT, getChange()=9663.624718615896]
Stock [getCurrentPrice()=46.325056780865076, getName()=Microsoft,
getNextPrice()=0.8851188863349135, getSymbol()=MSFT, getChange()=5133.766615543269]
Stock [getCurrentPrice()=50.957562458951585, getName()=Microsoft,
getNextPrice()=0.3060326511633442, getSymbol()=MSFT, getChange()=16551.021472788245]
Stock [getCurrentPrice()=48.409684336004005, getName()=Microsoft,
getNextPrice()=0.8275324836988968, getSymbol()=MSFT, getChange()=5749.883272209794]
Stock [getCurrentPrice()=45.98920011920381, getName()=Microsoft,
getNextPrice()=0.10308429295086907, getSymbol()=MSFT, getChange()=44513.19838622038]
Stock [getCurrentPrice()=50.588120131124185, getName()=Microsoft,
getNextPrice()=0.8998662915871091, getSymbol()=MSFT, getChange()=5521.737429668699]
Stock [getCurrentPrice()=48.05871412456798, getName()=Microsoft,
getNextPrice()=0.3093987686587141, getSymbol()=MSFT, getChange()=15432.936453790384]
Stock [getCurrentPrice()=52.86458553702477, getName()=Microsoft,
getNextPrice()=0.9828316042651137, getSymbol()=MSFT, getChange()=5278.803989168914]
Stock [getCurrentPrice()=51.27864797091403, getName()=Microsoft,
getNextPrice()=0.5408369199281408, getSymbol()=MSFT, getChange()=9381.351232036315]
Stock [getCurrentPrice()=47.68914261295005, getName()=Microsoft,
getNextPrice()=0.08967282961650136, getSymbol()=MSFT, getChange()=53081.26216926517]
Stock [getCurrentPrice()=47.21225118682055, getName()=Microsoft,
getNextPrice()=0.4991028371086679, getSymbol()=MSFT, getChange()=9359.42352488395]
Stock [getCurrentPrice()=44.851638627479524, getName()=Microsoft,
getNextPrice()=0.7109658837040591, getSymbol()=MSFT, getChange()=6208.55005219197]
Stock [getCurrentPrice()=40.81499115100637, getName()=Microsoft,
getNextPrice()=0.45785541489066717, getSymbol()=MSFT, getChange()=8814.384284556887]
Stock [getCurrentPrice()=41.63129097402649, getName()=Microsoft,
getNextPrice()=0.13170820207656408, getSymbol()=MSFT,
getChange()=31508.730753021406]
Stock [getCurrentPrice()=44.96179425194861, getName()=Microsoft,
getNextPrice()=0.5023516605536775, getSymbol()=MSFT, getChange()=8850.262890022701]
Stock [getCurrentPrice()=45.86103013698758, getName()=Microsoft,
getNextPrice()=0.07291978126369192, getSymbol()=MSFT, getChange()=62792.44062752368]
Stock [getCurrentPrice()=45.40241983561771, getName()=Microsoft,
getNextPrice()=0.6163054904769474, getSymbol()=MSFT, getChange()=7266.869277844924]
Stock [getCurrentPrice()=43.13229884383682, getName()=Microsoft,
getNextPrice()=0.7970084871836961, getSymbol()=MSFT, getChange()=5311.774094934525]
Stock [getCurrentPrice()=43.994944820713556, getName()=Microsoft,
getNextPrice()=0.8462533784207883, getSymbol()=MSFT, getChange()=5098.791040907095]
Stock [getCurrentPrice()=40.03539978684934, getName()=Microsoft,
getNextPrice()=0.12273386229892036, getSymbol()=MSFT,
getChange()=32519.685420917056]
Stock [getCurrentPrice()=44.03893976553427, getName()=Microsoft,
getNextPrice()=0.17824893089938232, getSymbol()=MSFT, getChange()=24606.42575152011]
Stock [getCurrentPrice()=40.07543518663619, getName()=Microsoft,
getNextPrice()=0.4424235337399539, getSymbol()=MSFT, getChange()=8958.16081885725]
Solution
import java.util.Random;
//defines the Stock class
public class Stock {
private String symbol;
private String name;
private double nextPrice;
private double currentPrice;
private double priceChange;
private double priceChangePercentage;
public Stock(String s, String n, double CP, double NP) {
symbol = s;
name = n;
nextPrice = NP;
currentPrice = CP;
}
public Stock() {
name = "Microsoft";
symbol = "MSFT";
nextPrice = 46.87;
currentPrice = 46.87;
}
public void setNextPrice(double nextPrice) {
if (nextPrice > 0)
this.nextPrice = nextPrice;
else
this.nextPrice = 0;
}
public void setCurrentPrice(double cPrice) {
if (currentPrice > 0) {
currentPrice = cPrice;
} else {
currentPrice = 0;
}
}
public double getCurrentPrice() {
return currentPrice;
}
public String getName() {
return name;
}
public void setName(String n) {
name = n;
}
public double getNextPrice() {
Random rand = new Random();
nextPrice = rand.nextDouble();
return nextPrice;
}
public String getSymbol() {
return symbol;
}
public void setSymbol(String s) {
symbol = s;
}
public double getChange() {
// formula : (current - next) / next * 100
priceChange = (currentPrice - nextPrice) / nextPrice * 100;
return priceChange;
}
public double SimulatePrice() {
Random rand = new Random();
priceChangePercentage = rand.nextInt(10) + 1;
if (priceChangePercentage % 2 == 0)
currentPrice += (currentPrice * (priceChangePercentage / 100.0));
else
currentPrice -= (currentPrice * (priceChangePercentage / 100.0));
return priceChangePercentage;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Stock [getCurrentPrice()=" + getCurrentPrice() + ", getName()="
+ getName() + ", getNextPrice()=" + getNextPrice()
+ ", getSymbol()=" + getSymbol() + ", getChange()="
+ getChange() + "]";
}
}
import java.util.Scanner;
public class StockPriceSimulator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String symbol;
String name;
double nextPrice;
double currentPrice;
System.out.print("Please enter the name of the stock:");
name = input.nextLine();
System.out.print("Please enter the symbol of the stock: ");
symbol = input.nextLine();
System.out.print("Please enter Current price of " + name + ":");
currentPrice = input.nextDouble();
System.out.print("Please enter next price of " + name + ":");
nextPrice = input.nextDouble();
Stock stock;
if (name.equals("NONE") || symbol.equals("NA") || currentPrice == 0.0
|| nextPrice == 0.0)
stock = new Stock();
else
stock = new Stock(symbol, name, currentPrice, nextPrice);
for (int i = 0; i < 30; i++) {
stock.SimulatePrice();
System.out.println(stock);
}
input.close();
}
}
OUTPUT:
Please enter the name of the stock:NONE
Please enter the symbol of the stock: DD
Please enter Current price of NONE:99
Please enter next price of NONE:98
Stock [getCurrentPrice()=51.556999999999995, getName()=Microsoft,
getNextPrice()=0.22684389480238243, getSymbol()=MSFT,
getChange()=22627.964552413654]
Stock [getCurrentPrice()=52.588139999999996, getName()=Microsoft,
getNextPrice()=0.8209357260355085, getSymbol()=MSFT, getChange()=6305.877869874233]
Stock [getCurrentPrice()=49.958732999999995, getName()=Microsoft,
getNextPrice()=0.36265111054409815, getSymbol()=MSFT,
getChange()=13675.976840397692]
Stock [getCurrentPrice()=53.95543163999999, getName()=Microsoft,
getNextPrice()=0.9724883297228907, getSymbol()=MSFT, getChange()=5448.182943786535]
Stock [getCurrentPrice()=49.0994427924, getName()=Microsoft,
getNextPrice()=0.43696372926786653, getSymbol()=MSFT,
getChange()=11136.503055909514]
Stock [getCurrentPrice()=51.063420504096, getName()=Microsoft,
getNextPrice()=0.11437740167806576, getSymbol()=MSFT, getChange()=44544.67609416631]
Stock [getCurrentPrice()=46.467712658727365, getName()=Microsoft,
getNextPrice()=0.08938738995292295, getSymbol()=MSFT, getChange()=51884.63976093294]
Stock [getCurrentPrice()=44.144327025791, getName()=Microsoft,
getNextPrice()=0.5339893602734628, getSymbol()=MSFT, getChange()=8166.892621827545]
Stock [getCurrentPrice()=46.79298664733846, getName()=Microsoft,
getNextPrice()=0.47925834918788124, getSymbol()=MSFT, getChange()=9663.624718615896]
Stock [getCurrentPrice()=46.325056780865076, getName()=Microsoft,
getNextPrice()=0.8851188863349135, getSymbol()=MSFT, getChange()=5133.766615543269]
Stock [getCurrentPrice()=50.957562458951585, getName()=Microsoft,
getNextPrice()=0.3060326511633442, getSymbol()=MSFT, getChange()=16551.021472788245]
Stock [getCurrentPrice()=48.409684336004005, getName()=Microsoft,
getNextPrice()=0.8275324836988968, getSymbol()=MSFT, getChange()=5749.883272209794]
Stock [getCurrentPrice()=45.98920011920381, getName()=Microsoft,
getNextPrice()=0.10308429295086907, getSymbol()=MSFT, getChange()=44513.19838622038]
Stock [getCurrentPrice()=50.588120131124185, getName()=Microsoft,
getNextPrice()=0.8998662915871091, getSymbol()=MSFT, getChange()=5521.737429668699]
Stock [getCurrentPrice()=48.05871412456798, getName()=Microsoft,
getNextPrice()=0.3093987686587141, getSymbol()=MSFT, getChange()=15432.936453790384]
Stock [getCurrentPrice()=52.86458553702477, getName()=Microsoft,
getNextPrice()=0.9828316042651137, getSymbol()=MSFT, getChange()=5278.803989168914]
Stock [getCurrentPrice()=51.27864797091403, getName()=Microsoft,
getNextPrice()=0.5408369199281408, getSymbol()=MSFT, getChange()=9381.351232036315]
Stock [getCurrentPrice()=47.68914261295005, getName()=Microsoft,
getNextPrice()=0.08967282961650136, getSymbol()=MSFT, getChange()=53081.26216926517]
Stock [getCurrentPrice()=47.21225118682055, getName()=Microsoft,
getNextPrice()=0.4991028371086679, getSymbol()=MSFT, getChange()=9359.42352488395]
Stock [getCurrentPrice()=44.851638627479524, getName()=Microsoft,
getNextPrice()=0.7109658837040591, getSymbol()=MSFT, getChange()=6208.55005219197]
Stock [getCurrentPrice()=40.81499115100637, getName()=Microsoft,
getNextPrice()=0.45785541489066717, getSymbol()=MSFT, getChange()=8814.384284556887]
Stock [getCurrentPrice()=41.63129097402649, getName()=Microsoft,
getNextPrice()=0.13170820207656408, getSymbol()=MSFT,
getChange()=31508.730753021406]
Stock [getCurrentPrice()=44.96179425194861, getName()=Microsoft,
getNextPrice()=0.5023516605536775, getSymbol()=MSFT, getChange()=8850.262890022701]
Stock [getCurrentPrice()=45.86103013698758, getName()=Microsoft,
getNextPrice()=0.07291978126369192, getSymbol()=MSFT, getChange()=62792.44062752368]
Stock [getCurrentPrice()=45.40241983561771, getName()=Microsoft,
getNextPrice()=0.6163054904769474, getSymbol()=MSFT, getChange()=7266.869277844924]
Stock [getCurrentPrice()=43.13229884383682, getName()=Microsoft,
getNextPrice()=0.7970084871836961, getSymbol()=MSFT, getChange()=5311.774094934525]
Stock [getCurrentPrice()=43.994944820713556, getName()=Microsoft,
getNextPrice()=0.8462533784207883, getSymbol()=MSFT, getChange()=5098.791040907095]
Stock [getCurrentPrice()=40.03539978684934, getName()=Microsoft,
getNextPrice()=0.12273386229892036, getSymbol()=MSFT,
getChange()=32519.685420917056]
Stock [getCurrentPrice()=44.03893976553427, getName()=Microsoft,
getNextPrice()=0.17824893089938232, getSymbol()=MSFT, getChange()=24606.42575152011]
Stock [getCurrentPrice()=40.07543518663619, getName()=Microsoft,
getNextPrice()=0.4424235337399539, getSymbol()=MSFT, getChange()=8958.16081885725]

More Related Content

Similar to import java.util.Random;defines the Stock class public class S.pdf

How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error-   Exception in thread -main- q- Exit java-lang-.pdfHow to fix this error-   Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdfaarokyaaqua
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfsharnapiyush773
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfarchanaemporium
 
So Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdfSo Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdfarihantgiftgallery
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfforwardcom41
 
Java code to find the closest pair using divide and conquer algorith.pdf
Java code to find the closest pair using divide and conquer algorith.pdfJava code to find the closest pair using divide and conquer algorith.pdf
Java code to find the closest pair using divide and conquer algorith.pdffashioncollection2
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfanwarsadath111
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by HowardLearningTech
 
Howard type script
Howard   type scriptHoward   type script
Howard type scriptLearningTech
 
Type script by Howard
Type script by HowardType script by Howard
Type script by HowardLearningTech
 
I need help for my next project due next tuesday can you help me in .pdf
I need help for my next project due next tuesday can you help me in .pdfI need help for my next project due next tuesday can you help me in .pdf
I need help for my next project due next tuesday can you help me in .pdfamritashinfosalys
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wildJoe Morgan
 
How can I add multiple names and addresses- To the following code- Tab.pdf
How can I add multiple names and addresses- To the following code- Tab.pdfHow can I add multiple names and addresses- To the following code- Tab.pdf
How can I add multiple names and addresses- To the following code- Tab.pdfThomasXUMParsonsx
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfatulkapoor33
 
Please find my solution.Please let me know in case of any issue..pdf
Please find my solution.Please let me know in case of any issue..pdfPlease find my solution.Please let me know in case of any issue..pdf
Please find my solution.Please let me know in case of any issue..pdfpremkhatri99
 
1 OverviewFor this lab, you will implement the insert method and t.pdf
1 OverviewFor this lab, you will implement the insert method and t.pdf1 OverviewFor this lab, you will implement the insert method and t.pdf
1 OverviewFor this lab, you will implement the insert method and t.pdfrajeshjain2109
 

Similar to import java.util.Random;defines the Stock class public class S.pdf (20)

How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error-   Exception in thread -main- q- Exit java-lang-.pdfHow to fix this error-   Exception in thread -main- q- Exit java-lang-.pdf
How to fix this error- Exception in thread -main- q- Exit java-lang-.pdf
 
package employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdfpackage employeeType.employee;public class Employee {    private.pdf
package employeeType.employee;public class Employee {    private.pdf
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
So Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdfSo Far I have these two classes but I need help with my persontest c.pdf
So Far I have these two classes but I need help with my persontest c.pdf
 
Java questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdfJava questionI am having issues returning the score sort in numeri.pdf
Java questionI am having issues returning the score sort in numeri.pdf
 
Java code to find the closest pair using divide and conquer algorith.pdf
Java code to find the closest pair using divide and conquer algorith.pdfJava code to find the closest pair using divide and conquer algorith.pdf
Java code to find the closest pair using divide and conquer algorith.pdf
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
 
Howard type script
Howard   type scriptHoward   type script
Howard type script
 
Type script by Howard
Type script by HowardType script by Howard
Type script by Howard
 
I need help for my next project due next tuesday can you help me in .pdf
I need help for my next project due next tuesday can you help me in .pdfI need help for my next project due next tuesday can you help me in .pdf
I need help for my next project due next tuesday can you help me in .pdf
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wild
 
How can I add multiple names and addresses- To the following code- Tab.pdf
How can I add multiple names and addresses- To the following code- Tab.pdfHow can I add multiple names and addresses- To the following code- Tab.pdf
How can I add multiple names and addresses- To the following code- Tab.pdf
 
ddd+scala
ddd+scaladdd+scala
ddd+scala
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdf
 
Please find my solution.Please let me know in case of any issue..pdf
Please find my solution.Please let me know in case of any issue..pdfPlease find my solution.Please let me know in case of any issue..pdf
Please find my solution.Please let me know in case of any issue..pdf
 
1 OverviewFor this lab, you will implement the insert method and t.pdf
1 OverviewFor this lab, you will implement the insert method and t.pdf1 OverviewFor this lab, you will implement the insert method and t.pdf
1 OverviewFor this lab, you will implement the insert method and t.pdf
 

More from aquazac

Answer Every investor expects dividend from his investments.Dividen.pdf
Answer Every investor expects dividend from his investments.Dividen.pdfAnswer Every investor expects dividend from his investments.Dividen.pdf
Answer Every investor expects dividend from his investments.Dividen.pdfaquazac
 
Ans. Gene is defined as the segment of DNA that gives a functional p.pdf
Ans. Gene is defined as the segment of DNA that gives a functional p.pdfAns. Gene is defined as the segment of DNA that gives a functional p.pdf
Ans. Gene is defined as the segment of DNA that gives a functional p.pdfaquazac
 
additional optmization techniques for underlying IP network must1.pdf
additional optmization techniques for underlying IP network must1.pdfadditional optmization techniques for underlying IP network must1.pdf
additional optmization techniques for underlying IP network must1.pdfaquazac
 
According to the given equation, aqueous carbon dioxide reacts with .pdf
According to the given equation, aqueous carbon dioxide reacts with .pdfAccording to the given equation, aqueous carbon dioxide reacts with .pdf
According to the given equation, aqueous carbon dioxide reacts with .pdfaquazac
 
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdfa) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdfaquazac
 
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdfaquazac
 
A person may not choose to participate in the labour force due to La.pdf
A person may not choose to participate in the labour force due to La.pdfA person may not choose to participate in the labour force due to La.pdf
A person may not choose to participate in the labour force due to La.pdfaquazac
 
Well.. 1) Ionic bonds are almost always metal to .pdf
                     Well.. 1) Ionic bonds are almost always metal to .pdf                     Well.. 1) Ionic bonds are almost always metal to .pdf
Well.. 1) Ionic bonds are almost always metal to .pdfaquazac
 
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdfaquazac
 
clear clc close all Use polyfit to solve for the phase l.pdf
 clear clc close all Use polyfit to solve for the phase l.pdf clear clc close all Use polyfit to solve for the phase l.pdf
clear clc close all Use polyfit to solve for the phase l.pdfaquazac
 
The oxygen appears in both step reactions. But, i.pdf
                     The oxygen appears in both step reactions. But, i.pdf                     The oxygen appears in both step reactions. But, i.pdf
The oxygen appears in both step reactions. But, i.pdfaquazac
 
PART A The element Si belongs to IVA group. Therefore, four electro.pdf
  PART A The element Si belongs to IVA group. Therefore, four electro.pdf  PART A The element Si belongs to IVA group. Therefore, four electro.pdf
PART A The element Si belongs to IVA group. Therefore, four electro.pdfaquazac
 
The two contributions to the cohesive energy of t.pdf
                     The two contributions to the cohesive energy of t.pdf                     The two contributions to the cohesive energy of t.pdf
The two contributions to the cohesive energy of t.pdfaquazac
 
If you are talking about an extraction design, th.pdf
                     If you are talking about an extraction design, th.pdf                     If you are talking about an extraction design, th.pdf
If you are talking about an extraction design, th.pdfaquazac
 
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdfYes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdfaquazac
 
When something boils, it changes states of matter. It would go from .pdf
When something boils, it changes states of matter. It would go from .pdfWhen something boils, it changes states of matter. It would go from .pdf
When something boils, it changes states of matter. It would go from .pdfaquazac
 
We need to discuss why there is an importance of adding residents to.pdf
We need to discuss why there is an importance of adding residents to.pdfWe need to discuss why there is an importance of adding residents to.pdf
We need to discuss why there is an importance of adding residents to.pdfaquazac
 
What is the largest decimal integer that can be represented with the.pdf
What is the largest decimal integer that can be represented with the.pdfWhat is the largest decimal integer that can be represented with the.pdf
What is the largest decimal integer that can be represented with the.pdfaquazac
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfaquazac
 
This electron transport is accompanied by the protons transfer into .pdf
This electron transport is accompanied by the protons transfer into .pdfThis electron transport is accompanied by the protons transfer into .pdf
This electron transport is accompanied by the protons transfer into .pdfaquazac
 

More from aquazac (20)

Answer Every investor expects dividend from his investments.Dividen.pdf
Answer Every investor expects dividend from his investments.Dividen.pdfAnswer Every investor expects dividend from his investments.Dividen.pdf
Answer Every investor expects dividend from his investments.Dividen.pdf
 
Ans. Gene is defined as the segment of DNA that gives a functional p.pdf
Ans. Gene is defined as the segment of DNA that gives a functional p.pdfAns. Gene is defined as the segment of DNA that gives a functional p.pdf
Ans. Gene is defined as the segment of DNA that gives a functional p.pdf
 
additional optmization techniques for underlying IP network must1.pdf
additional optmization techniques for underlying IP network must1.pdfadditional optmization techniques for underlying IP network must1.pdf
additional optmization techniques for underlying IP network must1.pdf
 
According to the given equation, aqueous carbon dioxide reacts with .pdf
According to the given equation, aqueous carbon dioxide reacts with .pdfAccording to the given equation, aqueous carbon dioxide reacts with .pdf
According to the given equation, aqueous carbon dioxide reacts with .pdf
 
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdfa) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
a) mean = 1.43Thus distribution is Poisson(4.2)P(X = 4) = 4.2^4.pdf
 
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
2.a. Wired Media Type and ExplinationTwisted-Pair CableTwiste.pdf
 
A person may not choose to participate in the labour force due to La.pdf
A person may not choose to participate in the labour force due to La.pdfA person may not choose to participate in the labour force due to La.pdf
A person may not choose to participate in the labour force due to La.pdf
 
Well.. 1) Ionic bonds are almost always metal to .pdf
                     Well.. 1) Ionic bonds are almost always metal to .pdf                     Well.. 1) Ionic bonds are almost always metal to .pdf
Well.. 1) Ionic bonds are almost always metal to .pdf
 
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
1. The answer is d) Environmental EffectsEnvironmental effects ca.pdf
 
clear clc close all Use polyfit to solve for the phase l.pdf
 clear clc close all Use polyfit to solve for the phase l.pdf clear clc close all Use polyfit to solve for the phase l.pdf
clear clc close all Use polyfit to solve for the phase l.pdf
 
The oxygen appears in both step reactions. But, i.pdf
                     The oxygen appears in both step reactions. But, i.pdf                     The oxygen appears in both step reactions. But, i.pdf
The oxygen appears in both step reactions. But, i.pdf
 
PART A The element Si belongs to IVA group. Therefore, four electro.pdf
  PART A The element Si belongs to IVA group. Therefore, four electro.pdf  PART A The element Si belongs to IVA group. Therefore, four electro.pdf
PART A The element Si belongs to IVA group. Therefore, four electro.pdf
 
The two contributions to the cohesive energy of t.pdf
                     The two contributions to the cohesive energy of t.pdf                     The two contributions to the cohesive energy of t.pdf
The two contributions to the cohesive energy of t.pdf
 
If you are talking about an extraction design, th.pdf
                     If you are talking about an extraction design, th.pdf                     If you are talking about an extraction design, th.pdf
If you are talking about an extraction design, th.pdf
 
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdfYes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
Yes ,its true. Though both gibbons and rhesus monkeys belong to pr.pdf
 
When something boils, it changes states of matter. It would go from .pdf
When something boils, it changes states of matter. It would go from .pdfWhen something boils, it changes states of matter. It would go from .pdf
When something boils, it changes states of matter. It would go from .pdf
 
We need to discuss why there is an importance of adding residents to.pdf
We need to discuss why there is an importance of adding residents to.pdfWe need to discuss why there is an importance of adding residents to.pdf
We need to discuss why there is an importance of adding residents to.pdf
 
What is the largest decimal integer that can be represented with the.pdf
What is the largest decimal integer that can be represented with the.pdfWhat is the largest decimal integer that can be represented with the.pdf
What is the largest decimal integer that can be represented with the.pdf
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
 
This electron transport is accompanied by the protons transfer into .pdf
This electron transport is accompanied by the protons transfer into .pdfThis electron transport is accompanied by the protons transfer into .pdf
This electron transport is accompanied by the protons transfer into .pdf
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 

Recently uploaded (20)

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 

import java.util.Random;defines the Stock class public class S.pdf

  • 1. import java.util.Random; //defines the Stock class public class Stock { private String symbol; private String name; private double nextPrice; private double currentPrice; private double priceChange; private double priceChangePercentage; public Stock(String s, String n, double CP, double NP) { symbol = s; name = n; nextPrice = NP; currentPrice = CP; } public Stock() { name = "Microsoft"; symbol = "MSFT"; nextPrice = 46.87; currentPrice = 46.87; } public void setNextPrice(double nextPrice) { if (nextPrice > 0) this.nextPrice = nextPrice; else this.nextPrice = 0; } public void setCurrentPrice(double cPrice) { if (currentPrice > 0) { currentPrice = cPrice; } else { currentPrice = 0; } } public double getCurrentPrice() {
  • 2. return currentPrice; } public String getName() { return name; } public void setName(String n) { name = n; } public double getNextPrice() { Random rand = new Random(); nextPrice = rand.nextDouble(); return nextPrice; } public String getSymbol() { return symbol; } public void setSymbol(String s) { symbol = s; } public double getChange() { // formula : (current - next) / next * 100 priceChange = (currentPrice - nextPrice) / nextPrice * 100; return priceChange; } public double SimulatePrice() { Random rand = new Random(); priceChangePercentage = rand.nextInt(10) + 1; if (priceChangePercentage % 2 == 0) currentPrice += (currentPrice * (priceChangePercentage / 100.0)); else currentPrice -= (currentPrice * (priceChangePercentage / 100.0)); return priceChangePercentage; } /* * (non-Javadoc) *
  • 3. * @see java.lang.Object#toString() */ @Override public String toString() { return "Stock [getCurrentPrice()=" + getCurrentPrice() + ", getName()=" + getName() + ", getNextPrice()=" + getNextPrice() + ", getSymbol()=" + getSymbol() + ", getChange()=" + getChange() + "]"; } } import java.util.Scanner; public class StockPriceSimulator { public static void main(String[] args) { Scanner input = new Scanner(System.in); String symbol; String name; double nextPrice; double currentPrice; System.out.print("Please enter the name of the stock:"); name = input.nextLine(); System.out.print("Please enter the symbol of the stock: "); symbol = input.nextLine(); System.out.print("Please enter Current price of " + name + ":"); currentPrice = input.nextDouble(); System.out.print("Please enter next price of " + name + ":"); nextPrice = input.nextDouble(); Stock stock; if (name.equals("NONE") || symbol.equals("NA") || currentPrice == 0.0 || nextPrice == 0.0) stock = new Stock(); else stock = new Stock(symbol, name, currentPrice, nextPrice); for (int i = 0; i < 30; i++) { stock.SimulatePrice(); System.out.println(stock);
  • 4. } input.close(); } } OUTPUT: Please enter the name of the stock:NONE Please enter the symbol of the stock: DD Please enter Current price of NONE:99 Please enter next price of NONE:98 Stock [getCurrentPrice()=51.556999999999995, getName()=Microsoft, getNextPrice()=0.22684389480238243, getSymbol()=MSFT, getChange()=22627.964552413654] Stock [getCurrentPrice()=52.588139999999996, getName()=Microsoft, getNextPrice()=0.8209357260355085, getSymbol()=MSFT, getChange()=6305.877869874233] Stock [getCurrentPrice()=49.958732999999995, getName()=Microsoft, getNextPrice()=0.36265111054409815, getSymbol()=MSFT, getChange()=13675.976840397692] Stock [getCurrentPrice()=53.95543163999999, getName()=Microsoft, getNextPrice()=0.9724883297228907, getSymbol()=MSFT, getChange()=5448.182943786535] Stock [getCurrentPrice()=49.0994427924, getName()=Microsoft, getNextPrice()=0.43696372926786653, getSymbol()=MSFT, getChange()=11136.503055909514] Stock [getCurrentPrice()=51.063420504096, getName()=Microsoft, getNextPrice()=0.11437740167806576, getSymbol()=MSFT, getChange()=44544.67609416631] Stock [getCurrentPrice()=46.467712658727365, getName()=Microsoft, getNextPrice()=0.08938738995292295, getSymbol()=MSFT, getChange()=51884.63976093294] Stock [getCurrentPrice()=44.144327025791, getName()=Microsoft, getNextPrice()=0.5339893602734628, getSymbol()=MSFT, getChange()=8166.892621827545] Stock [getCurrentPrice()=46.79298664733846, getName()=Microsoft, getNextPrice()=0.47925834918788124, getSymbol()=MSFT, getChange()=9663.624718615896] Stock [getCurrentPrice()=46.325056780865076, getName()=Microsoft, getNextPrice()=0.8851188863349135, getSymbol()=MSFT, getChange()=5133.766615543269] Stock [getCurrentPrice()=50.957562458951585, getName()=Microsoft, getNextPrice()=0.3060326511633442, getSymbol()=MSFT, getChange()=16551.021472788245] Stock [getCurrentPrice()=48.409684336004005, getName()=Microsoft, getNextPrice()=0.8275324836988968, getSymbol()=MSFT, getChange()=5749.883272209794]
  • 5. Stock [getCurrentPrice()=45.98920011920381, getName()=Microsoft, getNextPrice()=0.10308429295086907, getSymbol()=MSFT, getChange()=44513.19838622038] Stock [getCurrentPrice()=50.588120131124185, getName()=Microsoft, getNextPrice()=0.8998662915871091, getSymbol()=MSFT, getChange()=5521.737429668699] Stock [getCurrentPrice()=48.05871412456798, getName()=Microsoft, getNextPrice()=0.3093987686587141, getSymbol()=MSFT, getChange()=15432.936453790384] Stock [getCurrentPrice()=52.86458553702477, getName()=Microsoft, getNextPrice()=0.9828316042651137, getSymbol()=MSFT, getChange()=5278.803989168914] Stock [getCurrentPrice()=51.27864797091403, getName()=Microsoft, getNextPrice()=0.5408369199281408, getSymbol()=MSFT, getChange()=9381.351232036315] Stock [getCurrentPrice()=47.68914261295005, getName()=Microsoft, getNextPrice()=0.08967282961650136, getSymbol()=MSFT, getChange()=53081.26216926517] Stock [getCurrentPrice()=47.21225118682055, getName()=Microsoft, getNextPrice()=0.4991028371086679, getSymbol()=MSFT, getChange()=9359.42352488395] Stock [getCurrentPrice()=44.851638627479524, getName()=Microsoft, getNextPrice()=0.7109658837040591, getSymbol()=MSFT, getChange()=6208.55005219197] Stock [getCurrentPrice()=40.81499115100637, getName()=Microsoft, getNextPrice()=0.45785541489066717, getSymbol()=MSFT, getChange()=8814.384284556887] Stock [getCurrentPrice()=41.63129097402649, getName()=Microsoft, getNextPrice()=0.13170820207656408, getSymbol()=MSFT, getChange()=31508.730753021406] Stock [getCurrentPrice()=44.96179425194861, getName()=Microsoft, getNextPrice()=0.5023516605536775, getSymbol()=MSFT, getChange()=8850.262890022701] Stock [getCurrentPrice()=45.86103013698758, getName()=Microsoft, getNextPrice()=0.07291978126369192, getSymbol()=MSFT, getChange()=62792.44062752368] Stock [getCurrentPrice()=45.40241983561771, getName()=Microsoft, getNextPrice()=0.6163054904769474, getSymbol()=MSFT, getChange()=7266.869277844924] Stock [getCurrentPrice()=43.13229884383682, getName()=Microsoft, getNextPrice()=0.7970084871836961, getSymbol()=MSFT, getChange()=5311.774094934525] Stock [getCurrentPrice()=43.994944820713556, getName()=Microsoft, getNextPrice()=0.8462533784207883, getSymbol()=MSFT, getChange()=5098.791040907095] Stock [getCurrentPrice()=40.03539978684934, getName()=Microsoft, getNextPrice()=0.12273386229892036, getSymbol()=MSFT, getChange()=32519.685420917056] Stock [getCurrentPrice()=44.03893976553427, getName()=Microsoft, getNextPrice()=0.17824893089938232, getSymbol()=MSFT, getChange()=24606.42575152011]
  • 6. Stock [getCurrentPrice()=40.07543518663619, getName()=Microsoft, getNextPrice()=0.4424235337399539, getSymbol()=MSFT, getChange()=8958.16081885725] Solution import java.util.Random; //defines the Stock class public class Stock { private String symbol; private String name; private double nextPrice; private double currentPrice; private double priceChange; private double priceChangePercentage; public Stock(String s, String n, double CP, double NP) { symbol = s; name = n; nextPrice = NP; currentPrice = CP; } public Stock() { name = "Microsoft"; symbol = "MSFT"; nextPrice = 46.87; currentPrice = 46.87; } public void setNextPrice(double nextPrice) { if (nextPrice > 0) this.nextPrice = nextPrice; else this.nextPrice = 0; } public void setCurrentPrice(double cPrice) { if (currentPrice > 0) { currentPrice = cPrice; } else {
  • 7. currentPrice = 0; } } public double getCurrentPrice() { return currentPrice; } public String getName() { return name; } public void setName(String n) { name = n; } public double getNextPrice() { Random rand = new Random(); nextPrice = rand.nextDouble(); return nextPrice; } public String getSymbol() { return symbol; } public void setSymbol(String s) { symbol = s; } public double getChange() { // formula : (current - next) / next * 100 priceChange = (currentPrice - nextPrice) / nextPrice * 100; return priceChange; } public double SimulatePrice() { Random rand = new Random(); priceChangePercentage = rand.nextInt(10) + 1; if (priceChangePercentage % 2 == 0) currentPrice += (currentPrice * (priceChangePercentage / 100.0)); else currentPrice -= (currentPrice * (priceChangePercentage / 100.0)); return priceChangePercentage;
  • 8. } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return "Stock [getCurrentPrice()=" + getCurrentPrice() + ", getName()=" + getName() + ", getNextPrice()=" + getNextPrice() + ", getSymbol()=" + getSymbol() + ", getChange()=" + getChange() + "]"; } } import java.util.Scanner; public class StockPriceSimulator { public static void main(String[] args) { Scanner input = new Scanner(System.in); String symbol; String name; double nextPrice; double currentPrice; System.out.print("Please enter the name of the stock:"); name = input.nextLine(); System.out.print("Please enter the symbol of the stock: "); symbol = input.nextLine(); System.out.print("Please enter Current price of " + name + ":"); currentPrice = input.nextDouble(); System.out.print("Please enter next price of " + name + ":"); nextPrice = input.nextDouble(); Stock stock; if (name.equals("NONE") || symbol.equals("NA") || currentPrice == 0.0 || nextPrice == 0.0) stock = new Stock(); else
  • 9. stock = new Stock(symbol, name, currentPrice, nextPrice); for (int i = 0; i < 30; i++) { stock.SimulatePrice(); System.out.println(stock); } input.close(); } } OUTPUT: Please enter the name of the stock:NONE Please enter the symbol of the stock: DD Please enter Current price of NONE:99 Please enter next price of NONE:98 Stock [getCurrentPrice()=51.556999999999995, getName()=Microsoft, getNextPrice()=0.22684389480238243, getSymbol()=MSFT, getChange()=22627.964552413654] Stock [getCurrentPrice()=52.588139999999996, getName()=Microsoft, getNextPrice()=0.8209357260355085, getSymbol()=MSFT, getChange()=6305.877869874233] Stock [getCurrentPrice()=49.958732999999995, getName()=Microsoft, getNextPrice()=0.36265111054409815, getSymbol()=MSFT, getChange()=13675.976840397692] Stock [getCurrentPrice()=53.95543163999999, getName()=Microsoft, getNextPrice()=0.9724883297228907, getSymbol()=MSFT, getChange()=5448.182943786535] Stock [getCurrentPrice()=49.0994427924, getName()=Microsoft, getNextPrice()=0.43696372926786653, getSymbol()=MSFT, getChange()=11136.503055909514] Stock [getCurrentPrice()=51.063420504096, getName()=Microsoft, getNextPrice()=0.11437740167806576, getSymbol()=MSFT, getChange()=44544.67609416631] Stock [getCurrentPrice()=46.467712658727365, getName()=Microsoft, getNextPrice()=0.08938738995292295, getSymbol()=MSFT, getChange()=51884.63976093294] Stock [getCurrentPrice()=44.144327025791, getName()=Microsoft, getNextPrice()=0.5339893602734628, getSymbol()=MSFT, getChange()=8166.892621827545] Stock [getCurrentPrice()=46.79298664733846, getName()=Microsoft, getNextPrice()=0.47925834918788124, getSymbol()=MSFT, getChange()=9663.624718615896] Stock [getCurrentPrice()=46.325056780865076, getName()=Microsoft, getNextPrice()=0.8851188863349135, getSymbol()=MSFT, getChange()=5133.766615543269]
  • 10. Stock [getCurrentPrice()=50.957562458951585, getName()=Microsoft, getNextPrice()=0.3060326511633442, getSymbol()=MSFT, getChange()=16551.021472788245] Stock [getCurrentPrice()=48.409684336004005, getName()=Microsoft, getNextPrice()=0.8275324836988968, getSymbol()=MSFT, getChange()=5749.883272209794] Stock [getCurrentPrice()=45.98920011920381, getName()=Microsoft, getNextPrice()=0.10308429295086907, getSymbol()=MSFT, getChange()=44513.19838622038] Stock [getCurrentPrice()=50.588120131124185, getName()=Microsoft, getNextPrice()=0.8998662915871091, getSymbol()=MSFT, getChange()=5521.737429668699] Stock [getCurrentPrice()=48.05871412456798, getName()=Microsoft, getNextPrice()=0.3093987686587141, getSymbol()=MSFT, getChange()=15432.936453790384] Stock [getCurrentPrice()=52.86458553702477, getName()=Microsoft, getNextPrice()=0.9828316042651137, getSymbol()=MSFT, getChange()=5278.803989168914] Stock [getCurrentPrice()=51.27864797091403, getName()=Microsoft, getNextPrice()=0.5408369199281408, getSymbol()=MSFT, getChange()=9381.351232036315] Stock [getCurrentPrice()=47.68914261295005, getName()=Microsoft, getNextPrice()=0.08967282961650136, getSymbol()=MSFT, getChange()=53081.26216926517] Stock [getCurrentPrice()=47.21225118682055, getName()=Microsoft, getNextPrice()=0.4991028371086679, getSymbol()=MSFT, getChange()=9359.42352488395] Stock [getCurrentPrice()=44.851638627479524, getName()=Microsoft, getNextPrice()=0.7109658837040591, getSymbol()=MSFT, getChange()=6208.55005219197] Stock [getCurrentPrice()=40.81499115100637, getName()=Microsoft, getNextPrice()=0.45785541489066717, getSymbol()=MSFT, getChange()=8814.384284556887] Stock [getCurrentPrice()=41.63129097402649, getName()=Microsoft, getNextPrice()=0.13170820207656408, getSymbol()=MSFT, getChange()=31508.730753021406] Stock [getCurrentPrice()=44.96179425194861, getName()=Microsoft, getNextPrice()=0.5023516605536775, getSymbol()=MSFT, getChange()=8850.262890022701] Stock [getCurrentPrice()=45.86103013698758, getName()=Microsoft, getNextPrice()=0.07291978126369192, getSymbol()=MSFT, getChange()=62792.44062752368] Stock [getCurrentPrice()=45.40241983561771, getName()=Microsoft, getNextPrice()=0.6163054904769474, getSymbol()=MSFT, getChange()=7266.869277844924] Stock [getCurrentPrice()=43.13229884383682, getName()=Microsoft, getNextPrice()=0.7970084871836961, getSymbol()=MSFT, getChange()=5311.774094934525] Stock [getCurrentPrice()=43.994944820713556, getName()=Microsoft, getNextPrice()=0.8462533784207883, getSymbol()=MSFT, getChange()=5098.791040907095] Stock [getCurrentPrice()=40.03539978684934, getName()=Microsoft,
  • 11. getNextPrice()=0.12273386229892036, getSymbol()=MSFT, getChange()=32519.685420917056] Stock [getCurrentPrice()=44.03893976553427, getName()=Microsoft, getNextPrice()=0.17824893089938232, getSymbol()=MSFT, getChange()=24606.42575152011] Stock [getCurrentPrice()=40.07543518663619, getName()=Microsoft, getNextPrice()=0.4424235337399539, getSymbol()=MSFT, getChange()=8958.16081885725]