-1

別のクラスからメソッドを呼び出す必要がありますが、これに問題があります。把握しにくい。落札者の名前を表示する必要があります。if部分に入札値が記載されたprintlnに注意してください。

ガイドライン: PersonクラスのgetNameメソッドを使用する必要があります。まず、Personクラスのオブジェクトを取得する必要があります。これを行うには、highestBidオブジェクトを使用し、getBidderメソッドを呼び出します。Personオブジェクトを返します。そのオブジェクトを使用して、getName()メソッドを呼び出します。

これが私のコードです:

public void close(int lotNumber, String description)
{
     for(Lot lot : lots) 
     {
         System.out.println(lotNumber + description); //print lot number and description.
         Bid highestBid = lot.getHighestBid(); //get the highest bid for the lot.
         if (highestBid != null) 
         {
             System.out.println(bidder + highestBid.getValue()); //print bidder and highest bid value
            }     
         else
         {
             System.out.println("Not sold"); //if not sold print "Not sold"
            }
        }
}

ありがとうございました。

4

1 に答える 1

1

getName()が文字列を返すと仮定します。

public void close(int lotNumber, String description)
{
 for(Lot lot : lots) 
 {
     System.out.println(lotNumber + description); //print lot number and description.
     Bid highestBid = lot.getHighestBid(); //get the highest bid for the lot.
     if (highestBid != null) 
     {
         String name = highestBid.getBidder().getName();
         System.out.println(name + " " + highestBid.getValue()); //print bidder and highest bid value
        }     
     else
     {
         System.out.println("Not sold"); //if not sold print "Not sold"
        }
    }
}
于 2013-03-05T02:37:58.057 に答える