⑴ 用java定义一个股票类Stock,该类包括如右图所示
public class Stock {
private String store;// 股票类属性
private String symbol;// 股票代号
private String name;// 股票名称
private BigDecimal currentPrice;// 当前时间的股票价格
private BigDecimal previouClosingPrice;// 前一天的股票值
/**
* 返回前一天变到当前时间的百分比
* @return 百分比
*/
public double getChangePercent() {
return this.currentPrice.subtract(this.previouClosingPrice).abs()
.divide(this.currentPrice, 2, BigDecimal.ROUND_HALF_EVEN)
.doubleValue();
}
/**
* 返回前一天变到当前时间的百分比
* @param currentPrice 当前时间的股票价格
* @param previouClosingPrice 前一天的股票值
* @return 百分比
*/
public double getChangePercent(BigDecimal currentPrice,
BigDecimal previouClosingPrice) {
return currentPrice.subtract(previouClosingPrice).abs()
.divide(currentPrice, 2, BigDecimal.ROUND_HALF_EVEN)
.doubleValue();
}
public String getStore() {
return store;
}
public void setStore(String store) {
this.store = store;
}
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 BigDecimal getCurrentPrice() {
return currentPrice;
}
public void setCurrentPrice(BigDecimal currentPrice) {
this.currentPrice = currentPrice;
}
public BigDecimal getPreviouClosingPrice() {
return previouClosingPrice;
}
public void setPreviouClosingPrice(BigDecimal previouClosingPrice) {
this.previouClosingPrice = previouClosingPrice;
}
}
⑵ 用c++ 定义一个类Stock,记录一支股票交易的基本信息。
你是不愿意写代码吧,这个不难啊,基本学过类的都会
定义类Stock,里面有上述的私有成员变量,以及各个成员变量的公有set
和
get方法
再在main函数中创建连个变量
Stock
todayStock;
Stock
yesterdayStock;
再分别调用set函数,然后再计算涨幅、输出,很简单啊
⑶ c++程序设计题:定义一个股票类(stock)对象数组,存放连续5个交易日的股票信息,计算股票涨幅。
#include<iostream>
usingnamespacestd;
intmain()
{
doublestock[5];//定义长度为5的数组存放用户输入的股票价格
for(inti=0;i<5;i++)
{
cin>>stock[i];
}//循环读入用户输入的股价
doublepercent=(stock[4]-stock[0])*100;
cout<<"涨幅:"<<percent<<"%"<<endl;
return0;
}
⑷ 定义一个股票类Stock
定义股票的类:
在类模块中输入下列代码。
public symbol as string
public name as string
public currenprice as currency
public sub 显示股票信息()
msgbox(symbol & vbcrlf & name & currency)
end sub
打印图案
private sub print()
dim x as string
dim y as integer
dim z as integer
x=""
for i=0 to 2
y=2-i
z=1+i*2
for j=1 to y
x=x & " "
nex j
for j=1 to z
x=x & "#"
next j
x=x & vbcrlf
next i
msgbox(x)
end sub
没有看到第8题,第7题与股票的问题类似。
本例是用VB答复的,其他语言基本类似。
原来是要Java的:
public class Stock {
private String symbol;
private String name;
private double currentPrice;
public Stock(){
}
public void display(){
System.out.println("(" + this.symbol + ")" + this.name + ":" + this.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 getCurrentPrice() {
return currentPrice;
}
public void setCurrentPrice(double currentPrice) {
this.currentPrice = currentPrice;
}
}
⑸ 请求高手,帮我解决C++题
//多句费话,希望你以后自己做...如果不爱听就当我没说
#include <iostream>
#include <string>
using namespace std;
class Stock
{
public:
Stock(){};
Stock(char *p,int q=1000,double prs=9.89)
{
strcpy(sstockcode,p);
quan=q;
price=prs;
}
print()
{
cout<<this->sstockcode<<endl;
cout<<this->quan<<endl;
cout<<this->price<<endl;
}
private:
char sstockcode[10];//如果要动态的就用指针做,new
int quan;
double price;
};
void main()
{
Stock sk("kgddqypm",5,1.1);
sk.print();
}
⑹ java作业
实体类:
package test;
public class Stock implements Comparable<Stock>{
private String stockName;
private Integer stockadd;
@Override
public String toString() {
return "股票代码:"+stockName+",市盈率:"+stockadd+"%";
}
public Stock() {
super();
}
public Stock(String stockName, int stockadd) {
super();
this.stockName = stockName;
this.stockadd = stockadd;
}
public String getStockName() {
return stockName;
}
public void setStockName(String stockName) {
this.stockName = stockName;
}
public Integer getStockadd() {
return stockadd;
}
public void setStockadd(Integer stockadd) {
this.stockadd = stockadd;
}
public int compareTo(Stock stock) {
// return this.getStockadd().compareTo(stock.getStockadd()); //升序
return stock.getStockadd().compareTo(this.getStockadd()); //降序
}
}
测试类
package test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TestStock {
public static void main(String[] args) {
List<Stock> stockList = new ArrayList<Stock>();
for(int i = 10;i>0;i--){
Stock stock = new Stock();
stock.setStockName("招商银行"+i);
stock.setStockadd(10+i);
stockList.add(stock);
}
Collections.sort(stockList);
for(Stock sto:stockList){
System.out.println(sto);
}
}
}
主要就是实现Comparable这个接口,重写比较方法就行了。希望能帮到你
⑺ python 设计一个名为Stock的类来表示一个公司的股票
是的,设计一个名为 Stock的类表示股票,该类包括:
1、一个名为symbol的字符串数据域表示股票代码:
2、一个名为name的字符串数据域表示股票名称;
3、一个名为previousPrice的double型数据域,用来存储股票的前一 日收盘价:
4、一个名为currentPrice的double型数据域,用来存储股票的当前价格:
5、创建一个给定特定代码和名称的股票构造方法:
6、一个名为getChangePercentO方法,返回从前的日价格到当前价格变化的百分比。
实现这个类,编写个测试程序,创建一个Stock 对象,它的股票代码是600000,股票名称是“浦发银行”,前一日收盘价是 25.5元,当前的最新价是28.6元,显示市值变化的百分比。
拓展资料
设计一个Stock类和DividendStock类
编写了一个表示拥有股票情况的Stock类,这里给出了一个简化版,去掉了对参数的合法性的检查等细节,现在需要创建一个可以发放分红的股票。红利的多少和持有股票的数量成正比,不是所有的股票都是会有分红的,所以不能直接在Stock类上直接增加这个功能,而是应该在Stock类的基础上,继承一个DividendStock类。并在这个子类中增加分红的属性和行为。
(1)一个用于记录分红的字段dividents
(2)重写父类的getProfit方法(在父类的getProfit方法的基础上还要加上分红的)
父类的getProfit+股票的总的分红(也就是字段dividents的值)
(3)增加计算分红的方法,方法中的参数表示每股的红利,可以理解为成员变量dividents赋值: 股票的总的分红=每股的红利*总股数
public void payDividend(double amountPerShare)
编写一个测试的程序,创建一个名为”Oracle”的分红股票,先后以单价32元购买200股,以单价40元购买350股。每股的分红2.8元。这支股票的当前价格是每股50元。
⑻ 股票类Stock,定义一个对象数组存放连续5个交易日的股票信息
给你介绍一个学习布线的好去处,,红马褂散户之家,全免费的,每天老大时时推荐股票,要学习炒股技巧请到股市兵法栏目,找枫之雨就OK了
⑼ 用c++ 定义一个类Stock,记录一支股票交易的基本信息。
#include<iostream.h>
#include<graphics.h>
class Stock{
public:
Stock(int o,int h,int l,int c)
{
close=c;
open=o;
low=l;
high=h;
}
private:
int high;
int low;
int open;
int close;
};
int main()
{
Stock st(5,5.5,5,5.5);
Stock yesterday;
drawline(st); //未定义实现
yesterday=st;//有待您改进ing。
return 0;
}
⑽ 编写一个类Stock表示股票,成员变量有: string型symbol,表示股票代码. String型name,表示股票名称. double
其实这种最基础的题目,你自己想一下就做出来了。
public class Stock {
private String symbol;
private String name;
private double currentPrice;
public Stock(){
}
public void display(){
System.out.println("(" + this.symbol + ")" + this.name + ":" + this.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 getCurrentPrice() {
return currentPrice;
}
public void setCurrentPrice(double currentPrice) {
this.currentPrice = currentPrice;
}
}