淘宝代购网站建设/百度指数怎么做
题目:
设计一个Stock类,它包括
1.一个名为symbol的字符串数据域表示股票代码。
2.一个名为name的字符串数据域表示股票名字。
3.一个名为previousClosingPrice的double类型数据域,它存储的是前一日的股票值。
4.一个名为currentPrice的double类型数据域,它存储的是当时的股票值。
5.一个创建一只有特定代码的和名字的股票的构造方法。
6.一个名为getChangePercent()得到方法,返回previousClosingPrice到currentPrice变化的百分比。
画出该类的UML图并实现这个类,编写一个测试程序,创建一个Stock对象,他的股票代码是ORCL,股票名字为Oracle Corporation,前一日的收盘价是34.5。设置新的当前值为34.35,然后显示市值变化的百分比。
Stock:
package first;public class Stock {String symbol; //股票代码String name; //股票名字double previousClosingPrice; //前一日的股票值double currentPrice; //当时的股票值//一个创建一只有特定代码和名字的股票的构造方法public Stock(String symbolString, String name) {super();this.symbol = symbolString;this.name = name;this.previousClosingPrice = 0.0;this.currentPrice = 0.0;}//一个名为getChangePercent()的方法,返回从previousClosingPrice到currentPricepublic double getChangePercent(double previousClosingPrice,double currentPrice) {double ChangePercent = (previousClosingPrice - currentPrice)/previousClosingPrice *100;return ChangePercent;}}
StockTest:
package first;import static org.junit.jupiter.api.Assertions.*;import org.junit.jupiter.api.Test;class StockTest {@Testvoid test() {fail("Not yet implemented");}public StockTest() {// TODO Auto-generated constructor stubStock GuPiao = new Stock("ORCL", "Corporation");GuPiao.previousClosingPrice = 34.5;GuPiao.currentPrice = 34.35;System.out.print("The percentage of change in market value was ");System.out.printf("%.2f",GuPiao.getChangePercent(GuPiao.previousClosingPrice, GuPiao.currentPrice));System.out.println("%");}
}