9.2(股票类)

package hello;

public class Stock {
public static void main(String []args) {
	Stock stock1 = new Stock("ORCL","Oracle Corporation",34.5,34.35);
	System.out.println(stock1.getChangePercent(34.5, 34.35));
}

String symbol;
String name;
double previousClosingPrice;
double currentPrice;
public Stock(String newSymbol,String newName
		,double newPreviousClosingPrice,double 
		newCurrentPrice) {
	symbol = newSymbol;
	name = newName;
	previousClosingPrice = newPreviousClosingPrice;
	currentPrice = newCurrentPrice;
}
public Stock() {
    String symble;
    String name;
    double previousClosingPrice = 1;
    double currentPrice = 1;
}
String getChangePercent(double previousClosingPrice,double currentPrice) {
	double a = Math.abs(previousClosingPrice / currentPrice - 1) * 100;
	return a + "%";
}
}

猜你喜欢

转载自blog.csdn.net/weixin_39596963/article/details/79465295
9.2