2017-10-23 4 views
0

私はクラスで2日間過ごしましたが、いくつかのエラーを理解できません。CodeHSのクラスとサブクラスについて苦労して

私は実際にこのサイトで同様の質問を見つけましたが、まだそれを取得していません。

レッスンの名前は、「4.12.4 Clothing Store」です。

In this problem, you’ll design a few classes that represent different pieces of clothing in a clothing store.

You’ll write the classes for TShirt, Jeans, Sweatshirt and Clothing.

The Clothing class should have two instance variables: one for the size of the clothing (a String), and another for the clothing’s color (also a string).

Clothing should have two accessor (getter methods) as well:

public String getSize() 
public String getColor() 

The Sweatshirt class should have a private instance variable (or field) to store whether or not it has a hood, and a corresponding getter method

public boolean hasHood() 

The TShirt class should have a private field to store the fabric and a corresponding getter for that called

public String getFabric() 

All Jeans should have the color blue.

The constructors should be of this format:

public Clothing(String size, String color) 
public TShirt(String size, String color, String fabric) 
public Sweatshirt(String size, String color, boolean hasHood) 
public Jeans(String size) 

そして、次は私のコードです:

public class Clothing 
{ 
    public String size; 
    public String color; 

    public Clothing(String size, String color) 
    { 
     this.size = size; 
     this.color = color; 
    } 

    public String getSize() 
    { 
     return size; 
    } 

    public String getColor() 
    { 
     return color; 
    } 

} 


public class TShirt extends Clothing 
{ 
    private String fabric; 

    public TShirt(String size, String color, String fabric) 
    { 
     super(size, color); 
     this.fabric = fabric; 
    } 

    public String getFabric() 
    { 
     return fabric; 
    } 
} 


public class Sweatshirt extends Clothing 
{ 
    private boolean hasHood; 

    public Sweatshirt(String size, String color, boolean hasHood) 
    { 
     super(size, color); 
     this.hasHood = hasHood; 
    } 

    public boolean getHasHood() 
    { 
    return this.hasHood; 
    } 
} 


public class Jeans extends Clothing 
{ 
    public Jeans(String size) 
    { 
     super(size); 
    } 
} 

マイエラー:

Errors: Jeans.java: constructor Clothing in class Clothing cannot be applied to given types;

Grader.java: You may have forgotten to declare hasHood() or it's out of scope

+2

あなたの質問は何ですか?私はあなたが「得る」ことは理解していませんが、あなたが何を得ていないのか、何がうまくいかないのかは不明です。 – Makoto

答えて

1

Jeansは、スーパーコンストラクタに引数を1つだけ渡します。 Clothingの引数が1つしかないコンストラクタはありません。 Clothing(String size)またはJeansクラスをスーパーにデフォルト値を渡すことができます。 super(size, "Blue")など、適切なものを入力してください。

EDIT:hasHood()

変更getHasHood()。あなたのクラスはあなたに命名規則を強制しています。

+0

あなたが役に立ったら、それを受け入れられた答えとすることができます。 – mypetlion

+1

確かに、時間制限の直後にやるよ – IdiotWind