| 发表于:2007-03-29 08:09:07 楼主 |
这个控制台程序怎么写? 在下面代码中在标题处如果输入为空,我提示他不能为空,继续输入标题,就是下面的注解部分?还有我输入完一本书,我提示他还是否要输入另外一本.如果选择y 在重新输入谢谢 static void main(string[] args) { arraylist list = new arraylist(); bookclass ebook = new bookclass(); console.writeline( "input book title: "); string _title = console.readline(); //如果输入空有提示,但我还想停留在输入title 这个行里面,不是跳到input book author: ",也就是输入空,就叫他一直输入,直到不为空为止.要怎么写? ebook.title = _title; console.writeline( "input book author: "); string _author = console.readline(); ebook.author = _author; console.writeline( "input book cost: "); try { float _cost = float.parse(console.readline().tostring()); ebook.cost = _cost; } catch { console.writeline( "please input availibly float "); } console.writeline( "input book copies: "); try { int _copies = int.parse(console.readline().tostring()); } catch { console.writeline( "please input availibly int "); } console.readline(); // list.add(ebook); // foreach ( } class bookclass { private string title; private string author; private float cost; private int copies; public string title { get { return title; } set { if (value == " ") { console.writeline( "error, title not allow null ,please input again "); } else { title = value; } } } public string author { get { return author; } set { if (value == " ") { console.writeline( "error, author not allow null ,please input again "); } else { author = value; } } } public float cost { get { return cost; } set { if (value ==float.nan) { console.writeline( "error, cost not allow null ,please input again "); } else { cost = value; } } } public int copies { get { return copies; } set { if (value==null ) { console.writeline( "error, copies not allow null ,please input again "); } else { copies = value; } } } private void print() { console.writeline( "this book title is "+title+ " author is "+ author + " cost = " +cost.tostring()+ " copies= "+copies.tostring()); } } |
|
|
|
|