编写一个类STOCK表示股票,成员变量有:
String型symbol,表示股票代号
String型name,表示股票名称
double型previousClosingPrice,表示上期收盘价
double型currentPrice,表示当前价格
构造方法为:
Stock(String symbol,String name)用代号和名称创建股票对象
成员方法有:
所有成员变量的getter方法.
previousClosingPrice和currentPrice的setter方法
double changPercent(),返回该股票浮动的百分比:创建一个stock代号为,名称为ibm,上期收盘价176,当前价格为153,显示股票浮动的百分比class Stock {
double previousClosingPrice;
double currentPrice;
String symbol;
String name;
Stock(String symbol1,String name2){ }
double getpreviousClosingPrice() {
return previousClosingPrice;
}
void setpreviousClosingPrice(double p) {
previousClosingPrice = p;
}
double getcurrentPrice() {
return currentPrice;
}
void setcurrentPrice(double w) {
currentPrice = w;
}
String getsymbol() {
return symbol;
}
void setsymbol(String c) {
symbol = c;
}
void setVariables(double p, double w, String c){
previousClosingPrice = p;
currentPrice = w;
symbol = c;
}
void outputVariables(){
System.out.println(" 当前价:"+previousClosingPrice);
System.out.println(" 浮动的百分比为:"+currentPrice);
System.out.println(" name:"+symbol);
}
}
public class useStock{
public static void main(String[] args) {
Vehicle2 v = new Vehicle2();
v.setpreviousClosingPrice(176);
//v.setcurrentPrice(88.9);
v.setsymbol("IBM");
double i = v.getpreviousClosingPrice();
System.out.println("localValue="+i);
//System.out.println("weight="+v.getWeight());
System.out.println("symbol="+v.getsymbol());
v.setVariables(153, 0.23, "International Business Manufacture Inc");
v.outputVariables();
}
}
String型symbol,表示股票代号
String型name,表示股票名称
double型previousClosingPrice,表示上期收盘价
double型currentPrice,表示当前价格
构造方法为:
Stock(String symbol,String name)用代号和名称创建股票对象
成员方法有:
所有成员变量的getter方法.
previousClosingPrice和currentPrice的setter方法
double changPercent(),返回该股票浮动的百分比:创建一个stock代号为,名称为ibm,上期收盘价176,当前价格为153,显示股票浮动的百分比class Stock {
double previousClosingPrice;
double currentPrice;
String symbol;
String name;
Stock(String symbol1,String name2){ }
double getpreviousClosingPrice() {
return previousClosingPrice;
}
void setpreviousClosingPrice(double p) {
previousClosingPrice = p;
}
double getcurrentPrice() {
return currentPrice;
}
void setcurrentPrice(double w) {
currentPrice = w;
}
String getsymbol() {
return symbol;
}
void setsymbol(String c) {
symbol = c;
}
void setVariables(double p, double w, String c){
previousClosingPrice = p;
currentPrice = w;
symbol = c;
}
void outputVariables(){
System.out.println(" 当前价:"+previousClosingPrice);
System.out.println(" 浮动的百分比为:"+currentPrice);
System.out.println(" name:"+symbol);
}
}
public class useStock{
public static void main(String[] args) {
Vehicle2 v = new Vehicle2();
v.setpreviousClosingPrice(176);
//v.setcurrentPrice(88.9);
v.setsymbol("IBM");
double i = v.getpreviousClosingPrice();
System.out.println("localValue="+i);
//System.out.println("weight="+v.getWeight());
System.out.println("symbol="+v.getsymbol());
v.setVariables(153, 0.23, "International Business Manufacture Inc");
v.outputVariables();
}
}
2、这个构造方法有什么用啊
Stock(String symbol1,String name2){}
改成
Stock(String symbol,String name){
this.symbol = symbol;
this.name = name;
}
3、changePercent()根本也没看到(浮动百分比是什么意思我不懂,也就不写给你了)
4、Vehicle2 v = new Vehicle2(); Vehicle2从哪来啊
double previousClosingPrice;
double currentPrice;
String symbol;
String name; double getpreviousClosingPrice() {
return previousClosingPrice;
} void setpreviousClosingPrice(double p) {
previousClosingPrice = p;
} double getcurrentPrice() {
return currentPrice;
} void setcurrentPrice(double w) {
currentPrice = w;
} String getsymbol() {
return symbol;
} void setsymbol(String c) {
symbol = c;
} void setVariables(double p, double w, String c) {
previousClosingPrice = p;
currentPrice = w;
symbol = c;
} void outputVariables() {
System.out.println(" 当前价:" + previousClosingPrice);
System.out.println(" 浮动的百分比为:" + currentPrice);
System.out.println(" name:" + symbol);
}
}
public class UseStock {
public static void main(String[] args) {
Stock v = new Stock();
v.setpreviousClosingPrice(176);
// v.setcurrentPrice(88.9);
v.setsymbol("IBM");
double i = v.getpreviousClosingPrice();
System.out.println("localValue=" + i);
// System.out.println("weight="+v.getWeight());
System.out.println("symbol=" + v.getsymbol());
v.setVariables(153, 0.23, "International Business Manufacture Inc");
v.outputVariables();
}
}
那应该怎么修改?