companycallbackimpl.java
来自「用java写的股票交易游戏」· Java 代码 · 共 41 行
JAVA
41 行
// jingjing Wang
//420 final project
import java.rmi.*;
import java.rmi.server.*;
public class CompanyCallbackImpl extends UnicastRemoteObject implements
CompanyCallBackInterface {
private Company thiscompany;
/** Constructor */
public CompanyCallbackImpl(Object company) throws RemoteException {
thiscompany = (Company)company;
}
public void SellStock(int n,double bid){ //the company will sell the stock,n means the player wants to buy
int m=thiscompany.GetStock()-n;
thiscompany.SetStock(m);
double j=(bid*n+thiscompany.GetStock()*thiscompany.Getprice())/(thiscompany.GetStock()+n);
double k=(double)Math.round(j*100)/100;
thiscompany.SetPrice(k);
thiscompany.update();
}
public void BuyStock(int n,double bid){ // the company will buy the stock; n means the player wants to sell
int m=thiscompany.GetStock()+n;
thiscompany.SetStock(m);
double j=(bid*n+thiscompany.GetStock()*thiscompany.Getprice())/(thiscompany.GetStock()+n);
double k=(double)Math.round(j*100)/100;
thiscompany.SetPrice(k);
thiscompany.update();
} //endBuyStock
public int getStock(){
return thiscompany.stock;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?