Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TestStock.java
- public class TestStock {
- public static void main(String[] args) {
- Stock stock = new Stock("LKSS", "Limerick Software Solutions");
- stock.previousClosingPrice = 79.45;
- stock.currentPrice = 79.65;
- double percentageChange = stock.getChangePercent();
- System.out.printf("Name: %s\nPercent change: %.3f", stock.name, percentageChange);
- }
- }
- //Stock.java
- public class Stock {
- String symbol;
- String name;
- double previousClosingPrice;
- double currentPrice;
- Stock(String symbol, String name) {
- this.symbol = symbol;
- this.name = name;
- }
- double getChangePercent() {
- return ((currentPrice - previousClosingPrice) / previousClosingPrice) * 100;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement