Stock类
package com.sugarpie.classtest12;
/**
* @author sugarpie
* @create 2021-04-29-15:00
*/
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) / currentPrice * 100;
}
}
package com.sugarpie.classtest12;
/**
* @author sugarpie
* @create 2021-04-29-15:11
*/
public class StockTest {
public static void main(String[] args) {
Stock stock = new Stock("ORCL", "Oracle Corporation");
stock.previousClosingPrice = 34.5;
stock.currentPrice = 34.35;
System.out.println("市场变化:" + stock.getChangePercent() + "%");
}
}