Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. public class Stock {
  2. private String symbol;
  3. private String name;
  4. private double prevClosingPrice;
  5. private double currentPrice;
  6.  
  7.  
  8.  
  9.  
  10. public Stock(String vsymbol, String vname) {
  11. symbol = vsymbol;
  12. name = vname;
  13.  
  14. }
  15.  
  16. public double getChangePercent() {
  17. return ((getCurPrice() - getPrevClosingPrice()))/ getPrevClosingPrice();
  18. }
  19.  
  20. public void setName(String vName) {
  21. name = vName;
  22.  
  23. }
  24.  
  25. public void setPrevClsingPrice(double newPreviousClosingPrice) {
  26. prevClosingPrice = newPreviousClosingPrice;
  27.  
  28. }
  29.  
  30. public void setCurrentPrice(double newCurrentPrice) {
  31. currentPrice = newCurrentPrice;
  32. }
  33.  
  34. public String getName() {
  35. return name;
  36.  
  37. }
  38.  
  39. public double getPrevClosingPrice() {
  40. return prevClosingPrice;
  41. }
  42.  
  43. public double getCurPrice() {
  44. return currentPrice;
  45. }
  46.  
  47. public void displayInfo() {
  48. System.out.println("Stock name: " + getName());
  49. System.out.println("previous closing price: " + getPrevClosingPrice());
  50. System.out.println("Current Price: " + getCurPrice());
  51. System.out.println("Price change: " + getChangePercent() * 100+"%");
  52. }
  53.  
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement