2017-03-23 1 views
-4

내가 문자열로 생성자를 변경을 요청하는 오류가 계속하지만 난 그것이 LOCALDATE에게LOCALDATE 형식

공공 정적 무효 메인 (문자열 []에 인수) 할 필요가, 경매에 대한 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

스윙을 사용하지 않는다면 [ 'DateTimeFormatter'] (http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html) –

+0

내 경매 클래스의 생성자에서이를 사용해야합니까? –

답변

0

오류가 말한대로 따르고, 문자열에 생성자를 변경하는 것이 일을하는 한 가지 방법 :

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

나는 당신의 의견을 알고있는 것처럼 당신이 교류로 생성자를 원하는 LoaclDate을 cept. 이와 같이 :

Auction auction1 = new Auction(1000.00, 5000.00, LocalDate.of(2017, 4, 5)); 

이는 LocalDate 유형의 매개 변수로 생성자를 선언하는 문제입니다. 예를 들어 : 난 그냥 날짜 형식에 넣어 가지고

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()을 사용하지 않는 사람은 없습니다. 솔직히 당신이 잘 설명하지 못했기 때문에 내가 놓친 다른 것들이있을 것입니다.

관련 문제