爱问知识人 爱问教育 医院库

2 題 Java 程式

首页

2 題 Java 程式

可以把中間的Code ??出???
1. Complete the following definition of the static method OrderByCode that inputs an ArrayList items of MenuItems and returns a new ArrayList of MenuItems containing all the menu items (regardless of whether or not they are available) with all the appetizers listed first, all the entrees listed next, and all the desserts listed last.

Method: 
public static ArrayList<MenuItem> OrderByCode( ArrayList<MenuItem> items )
{

...?


}
ArrayList<MenuItem> items = new ArrayList<MenuItem>();
 d( new MenuItem( "Big Bad Burger", 9.95, 2.15, 1, true ) );
 d( new MenuItem( "Cheeky Chicken", 5.95, 0.75, 1, true ) );
 d( new MenuItem( "Wild Wings", 5.95, 0.50, 0, true ) );
 d( new MenuItem( "Flying Fish", 15.95, 7.61, 1, false ) );
 d( new MenuItem( "Igloo Icecream", 1.95, 0.28, 2, true ) );
ArrayList<MenuItem> ordered = OrderByCode( items );
for ( MenuItem item : ordered )
 intln(  nuString() );

Result: Wings, Burger, Chicken, Fish, Icecream ....

Hint: create a new ArrayList of MenuItems and add elements of the input to it, those with code 0 first, then those with code 1, and finally those with code 2. Finally, return the new ArrayList. 

2.  Complete the following definition of the static method AvailableItems that inputs an ArrayList items of MenuItems and returns a new ArrayList of MenuItems containing just those menu items that are currently available.

Method:
public static ArrayList<MenuItem> AvailableItems( ArrayList<MenuItem> items )
{
....?



}
ArrayList<MenuItem> items = new ArrayList<MenuItem>();
 d( new MenuItem( "Big Bad Burger", 9.95, 2.15, 1, false ) );
 d( new MenuItem( "Cheeky Chicken", 5.95, 0.75, 1, true ) );
 d( new MenuItem( "Wild Wings", 5.95, 0.50, 0, false ) );
 d( new MenuItem( "Flying Fish", 15.95, 7.61, 1, false ) );
 d( new MenuItem( "Igloo Icecream", 1.95, 0.28, 2, true ) );
ArrayList<MenuItem> available = AvailableItems( items );
for ( MenuItem item : available )
 intln(  nuString() );

Result: Cheeky Chicken ($5.95) and Igloo Icecream ($1.95)......

Hint: Just create a new ArrayList of MenuItems and add elements of the input to it according as they're available or not. Then return the new ArrayList. Five lines of code max in the body of the method. 

提交回答
好评回答
  • 2008-12-05 23:07:59
      1。 public static ArrayList AvailableItems( ArrayList items )
    {
    ArrayList temp = new ArrayList();
    for ( MenuItem item :items )
        if (item。
      Available()) d(new MenuItem(item。GetName(), item。GetPrice(), item。GetCost(), item。GetCode(), item。
      Available())); return temp; } public static void main(String[] args) { ArrayList items = new ArrayList(); d( new MenuItem( "Big Bad Burger", 9。
      95, 2。15, 1, false ) ); d( new MenuItem( "Cheeky Chicken", 5。95, 0。75, 1, true ) ); d( new MenuItem( "Wild Wings", 5。
      95, 0。50, 0, false ) ); d( new MenuItem( "Flying Fish", 15。95, 7。61, 1, false ) ); d( new MenuItem( "Igloo Icecream", 1。
      95, 0。28, 2, true ) ); ArrayList available = AvailableItems( items ); for ( MenuItem item : available ) intln( nuString() ); } } 2。
      public static ArrayList OrderByCode( ArrayList items ) { ArrayList temp = new ArrayList(); if ( Empty()) return temp; //?]有說code的範??要找出minimum, maximum int max= t(0)。
      GetCode(); int min=max; for ( MenuItem item : items ) { int code =item。GetCode(); if (code > max) max=code; if (code items = new ArrayList(); d( new MenuItem( "Big Bad Burger", 9。
      95, 2。15, 1, true ) ); d( new MenuItem( "Cheeky Chicken", 5。95, 0。75, 1, true ) ); d( new MenuItem( "Wild Wings", 5。95, 0。
      50, 0, true ) ); d( new MenuItem( "Flying Fish", 15。95, 7。61, 1, false ) ); d( new MenuItem( "Igloo Icecream", 1。95, 0。
      28, 2, true ) ); ArrayList ordered = OrderByCode( items ); for ( MenuItem item : ordered ) intln( nuString() ); } } 。
      

    王***

    2008-12-05 23:07:59

其他答案

    2008-12-05 22:44:54
  • 兄弟:你这题目我看了好几次 第一个看出个所以然来了,可MenuItem类的定义不知道,所以也不知道怎么去写,第二个题硬是连题目的意思都没搞懂,我很遗憾

    1***

    2008-12-05 22:44:54

类似问题

换一换

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 177-196
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):