设计一个名为 Stock的类表示股票,编写个测试程序,创建一个Stock 对象,实现这个类。

设计一个名为 Stock的类表示股票,该类包括:
●一个名为symbol的字符串数据域表示股票代码:
●一个名为name的字符串数据域表示股票名称;
●一个名为previousPrice的double型数据域,用来存储股票的前一 日收盘价:
●一个名为currentPrice的double型数据域,用来存储股票的当前价格:
●创建一个给定特定代码和名称的股票构造方法:
●一个名为getChangePercentO方法,返回从前日价格到 当前价格变化的百分比。
实现这个类。编写个测试程序,创建一个Stock 对象,它的股票代码是600000,股票名称是“浦发银行”,前一日收盘价是 25.5,当前的最新价是28.6,显示市值变化的百分比。
package Chapter_4;

public class Stock {
String symbol,name;
double previousPrice,currentPrice;
public String getSymbol() {
   return symbol;
}
public void setSymbol(String symbol) {
   this.symbol = symbol;
}
public String getName() {
   return name;
}
public void setName(String name) {
    this.name = name;
}
   public double getPreviousPrice() {
   return previousPrice;
}
public void setPreviousPrice(double previousPrice) {
   this.previousPrice = previousPrice;
}
public double getCurrentPrice() {
   return currentPrice;
}
public void setCurrentPrice(double currentPrice) {
   this.currentPrice = currentPrice;
}
public double getChangePercent() {
   return (this.currentPrice/this.previousPrice-1)*100;
}
   public static void main(String[] args) {
     // TODO Auto-generated method stub
Stock s=new Stock();
s.setSymbol("股票代码:600000");
s.setName("股票名称:浦发银行");
s.setPreviousPrice(25.5);
s.setCurrentPrice(28.6);
System.out.println(s.getSymbol());
System.out.println(s.getName());
System.out.printf("市值变化百分比为:"+"%.2f",s.getChangePercent());
System.out.println("%");
   }

}
  • 8
    点赞
  • 92
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值