导航:首页 > 编程语言 > python设计一个名为stock的类

python设计一个名为stock的类

发布时间:2024-01-21 15:54:39

python定义一个Dog类,实例化两个小狗对象。类属性有名字,颜色,体重。实现以下描述

程序写给你

classdogClass():

def__init__(self,name,color,weight):

self.name=name

self.color=color

self.weight=weight


def__del__(self):

self.name=""

self.color=""

self.weight=""


defname(self):

returnself.name


defcolor(self):

returnself.color


defweight(self):

returnself.weight


a=dogClass("旺财","棕色","5斤")


b=dogClass("来福","黑色","8斤")

print("小狗名字叫",a.name,",颜色是",a.color,",体重",a.weight)


print("小狗名字叫",b.name,",颜色是",b.color,",体重",b.weight)


执行结果:

⑵ 编写一个类Stock表示股票,成员变量有: string型symbol,表示股票代码. String型name,表示股票名称. double

private String symbol;//string型symbol,表示股票代码.
private String name;//String型name,表示股票名称.
private double previousClosingPrice;//double型previousClosingPrice,表示上期收盘价
private double currentPrice;//double型currentPrice,表示当前价格.
//下列为Set和get方法
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public String getName() {
return name;
}
public void setNameString(String nameString) {
this.name = nameString;
}
public double getPreviousClosingPrice() {
return previousClosingPrice;
}
public void setPreviousClosingPrice(double previousClosingPrice) {
this.previousClosingPrice = previousClosingPrice;
}
public double getCurrentPrice() {
return currentPrice;
}
public void setCurrentPrice(double currentPrice) {
this.currentPrice = currentPrice;
}
//Stock(String symbol,String name),用来创建股票对象
Stock(String symbol,String name,double previousClosingPrice,double currentPrice) {
this.symbol = symbol;
this.name = name;
this.previousClosingPrice = previousClosingPrice;
this.currentPrice = currentPrice;
}

double changePercent(){
return (currentPrice - previousClosingPrice) /previousClosingPrice;
}

public static void main(String[] args){
Stock stock = new Stock("IBM", "Intermational Business Manufacture Inc",176 , 153);
System.out.println(stock.name+"股票本月同比上月上涨"+stock.changePercent()+"个百分点!");
}

我也是学生啊 可以进行技术交流哦 希望这能帮助到你....

阅读全文

与python设计一个名为stock的类相关的资料

热点内容
linux字符设备驱动程序 浏览:57
全排列算法java 浏览:465
中国银行app转账电子回单在哪里 浏览:51
操作简单的程序员 浏览:598
数值积分算法求pi 浏览:16
按钮怎么连命令方块 浏览:909
房贷还清后不解压能贷款吗 浏览:36
程序员哄老婆开心技术 浏览:672
oracle自动备份压缩文件 浏览:853
遵义人字形加密网带 浏览:255
宁波人社在哪里下载app 浏览:92
好哒商户app下载在哪里下载 浏览:609
广发兑星巴克是在app哪里操作 浏览:783
linuxgetline 浏览:215
app的悬浮窗权限在哪里设置 浏览:686
51单片机定时器溢出标志 浏览:373
单片机烧写方法图解 浏览:399
遍历输出java 浏览:551
贵妃app直播哪里下载 浏览:273
android手机屏幕宽度和高度 浏览:816