2017-03-23 4 views
-4

私は文字列にコンストラクタを変更するように求めるエラーを取得しておいてくださいしかし、私はそれがLOCALDATEにLOCALDATE形式

のpublic static無効メイン(文字列[] args)である必要があり、オークションのためLOCALDATEをフォーマットすることができる方法{

user1 = new User("fred", "fredbloggs"); 
    user2 = new User("joe", "joebloggs"); 
    auction1 = new Auction(1000.00, 5000.00, 2017-04-05); 
    auction2 = new Auction(30.00, 80.00, ); 
    item1 = new Item("Car - Honda Civic VTI 1.8 Petrol"); 
    item2 = new Item("Sony Bluetooth Speakers"); 
+0

[DateFormatter](https://docs.oracle.com/javase/7/docs/api/javax/swing/text/DateFormatter.html)はあなたの友だちです – Jens

+0

Swingを使用していない場合は、 'DateTimeFormatter'](http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html) –

+0

私のオークション・クラスのコンストラクタでそれを使用する必要がありますか? –

答えて

0

エラーが言うように、次の文字列にあなたのコンストラクタを変更することですこれを行う1つの方法:

auction1 = new Auction(1000.00, 5000.00, "2017-04-05"); 
//rest of code 


//then change the class definition 
public class Auction{ 
    LocalDate auctionDate; 
    //declare other members here 

    public Auction(int startingPrice,int buyoutPrice,String auctionDate){ 
    this.auctionDate=auctionDate; 
    //set up other members accordingly 
    } 
} 
+0

残念ながら、これは私のプロジェクトの残りの部分で多くのエラーをもたらします。コンストラクタをローカル日付に保ちながら問題を解決する方法はありますか? –

0

は、私はあなたのコメントを理解するとして、あなたは、ACにあなたのコンストラクタをしたいですLoaclDateとしてください。このように:

タイプ LocalDateのパラメータでコンストラクタを宣言するの質問をだ
Auction auction1 = new Auction(1000.00, 5000.00, LocalDate.of(2017, 4, 5)); 

。例えば:私はちょうど日付形式に入れている

public class Auction { 

    private static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("EEEE d/L uuuu"); 

    // other instance fields 
    LocalDate auctionDate; 

    public Auction(double startingPrice, double buyoutPrice, LocalDate auctionDate) { 
     // set other instance fields 
     this.auctionDate = auctionDate; 
    } 

    // methods 

    public String getFormattedAuctionDate() { 
     return auctionDate.format(dateFormatter); 
    } 

} 

、それはほとんどあなたが書式設定したい場合は、独自のものを提供してくださいしたいとちょうどLocalDate.toString()を使用したくない1ません。あなたが正直に説明しなかったので、私が行方不明になっていることは他にもあります。

関連する問題