Advertisement
PadmaJS

stock

Sep 30th, 2022
2,885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.71 KB | None | 0 0
  1. //TestStock.java
  2. public class TestStock {
  3.   public static void main(String[] args) {
  4.     Stock stock = new Stock("LKSS", "Limerick Software Solutions");
  5.     stock.previousClosingPrice = 79.45;
  6.     stock.currentPrice = 79.65;
  7.     double percentageChange = stock.getChangePercent();
  8.     System.out.printf("Name: %s\nPercent change: %.3f", stock.name, percentageChange);
  9.   }
  10. }
  11.  
  12. //Stock.java
  13. public class Stock {
  14.   String symbol;
  15.   String name;
  16.   double previousClosingPrice;
  17.   double currentPrice;
  18.  
  19.   Stock(String symbol, String name) {
  20.     this.symbol = symbol;
  21.     this.name = name;
  22.   }
  23.  
  24.   double getChangePercent() {
  25.     return ((currentPrice - previousClosingPrice) / previousClosingPrice) * 100;
  26.   }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement