日期:2014-05-20  浏览次数:20779 次

编写程序出了点问题求救.有代码和题
编写一个类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();
}
}






------解决方案--------------------
给你改过来了,
Java code

public class Stock {
    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);
    }
}