写这样的课程是否正确?在的问题是该方法getPrice()的Item类.每个物品都需要有一个getPrice().但我实际上无法回复一些东西.所以我解雇了this.getPrice()让我得到的价格ProductItem.是否有更坚固/更好的设计解决方案?
class Item {
String description;
public Item(String description) {
this.description = description;
}
double getPrice(){return this.getPrice();} //TODO Correct like this?
}
class ProductItem extends Item {
int amount;
double pricePerUnit;
public ProductItem(String description, int amount, double pricePerUnit) {
super(description);
this.amount = amount;
this.pricePerUnit = pricePerUnit;
}
@Override
double getPrice(){
return amount * pricePerUnit;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个通过我的网址传递的参数,如下所示:
eu\test5.
当我打印这个字符串它说eu est5,它正在取代\t.
我怎样才能确保我的字符串没有任何东西?我想在反斜杠后获取所有数据,所以我有值test5.
string user = "eu\test5";
int backslashPos = user.IndexOf("\\");
label2.Text = user.Substring(backslashPos);
Run Code Online (Sandbox Code Playgroud) 所以我正在将这款智能手机应用程序模拟到Windows.这是一个运行它的逻辑和绘制方法的游戏1/60.这是毫秒16.6667
我实现了这个游戏循环:
private const double UPDATE_RATE = 1000d / 60d;
private void GameLoop()
{
double startTime;
while (GetStatus() != GameStatus.NotConnected)
{
startTime = Program.TimeInMillis;
//Update Logic
while (Program.TimeInMillis - startTime <= UPDATE_RATE)
{
//Thread.Yield(); it consumed CPU before adding this too, adding this had no effect
Thread.Sleep(TimeSpan.FromTicks(1));//don't eat my cpu
}
}
Debug.WriteLine("GameLoop shutdown");
}
Run Code Online (Sandbox Code Playgroud)
Program.TimeInMillis来自一个NanoStopwatch班级,以毫秒为单位返回时间double.这很有用,因为这个游戏循环必须非常准确才能使一切正常.
你可能知道,这里Thread.Sleep会耗费大量的CPU.可能是因为它需要int millis将我转换TimeSpan为0毫秒.
我最近遇到了这个叫做的东西WaitHandle,但我看到的一切都用了int millis.我真的需要让这个准确,所以我真的需要double millis …