2017-11-08 11 views
0

私はコピーコンストラクタを作成するために割り当てを行っていました。 しかし、コンストラクタのShoes(string、double)は未定義です。これはどういう意味ですか、コピーコンストラクタを得るためにこれを修正する方法は?コピーコンストラクタが定義されていません

public class Shoes { 


    //Instance Variables 
    private String brand; // The shoes brand 
    private String color; // The shoes color 
    private double size; // The shoes size 


    // Assigns instance variables to default values 
     public Shoes(){ 
      brand = ""; 
      color = ""; 
      size = 0; 
     } 

    //Constructor 
    public Shoes (String brand, String color, double size) 
    { 
     this.brand = brand; 
     this.color = color; 
     this.size = size; 
    } 


    /** 
    * The setBrand method stores a value in the brand field. 
    * @param brand The value to store in Brand. 
    */ 

    public void setBrand (String brand) 
    { 
     this.brand=brand; 
    } 

    /** 
    * The setColor method stores a value in the color field. 
    * @param color the value to store in color 
    */ 

    public void setColor (String color) 
    { 
     this.color=color; 
    } 

    /** 
    * The setSize method stores a value in the size field. 
    * @param size the value to store in size 
    */ 

    public void setSize (double size) 
    { 
     this.size=size; 
    } 

    /** 
    * The getBrand method returns Shoes brand. 
    * @return the value in the brand field 
    */ 

    public String getBrand() 
    { 
     return brand; 
    } 

    /** 
    * the getColor method returns Shoes color. 
    * @return the value in the color field 
    */ 

    public String getColor() 
    { 
     return color; 
    } 

    /** 
    * the getSize method returns Shoes size 
    * @return the value in the size field 
    */ 

    public double getSize() 
    { 
     return size; 
    } 
    public String toString() 
    { 
     String str = " My shoes " + brand + color + size; 
     return str; 
    } 
    public boolean equal(Shoes object2) 
    { 
     boolean status; 
     if (brand.equals(object2.brand) && 
       size == object2.size) 
       status = true; // Yes, the objects are equal. 
       else 
       status = false; // No, the objects are not equal. 

       // Return the value in status. 
       return status; 
    } 
    public Shoes copy() 
    { 
     Shoes copyObject = new Shoes(brand,size); 

    } 
    // prints out the values of all instance variables of your object 
    public void display() 
    { 
     System.out.println(brand); 
     System.out.println(color); 
     System.out.println(size); 

    } 


} 

これは、このプログラムを正常に実行するのに役立つ別のクラスです。

public class Demo { 

    public static void main(String[] args) { 
     // Create a object 
     Shoes shoes = new Shoes(); 

     //Call the object's setBrand method, passing Nike as a argument. 
     shoes.setBrand("Nike"); 

     //Call the object's setColor method, passing Pink as a argument. 
     shoes.setColor("Pink"); 

     //Call the object's setSize method, passing 7 as a argument. 
     shoes.setSize(7); 

     shoes.display(); 

      // Create a Stock object. 
      Shoes company1 = new Shoes("Nike",7.00); 

      // Declare a Stock variable 
      Shoes company2; 

      // Make company2 reference a copy of the object 
      // referenced by company1. 
      company2 = company1.copy(); 

      // Display the contents of both objects. 
      System.out.println("Company 1:\n" + company1); 
      System.out.println(); 
      System.out.println("Company 2:\n" + company2); 

      // Confirm that we actually have two objects. 
      if (company1 == company2) 
      { 
      System.out.println("The company1 and company2 " + 
         "variables reference the same object."); 
      } 
      else 
      { 
      System.out.println("The company1 and company2 " + 
        "variables reference different objects."); 
    } 

} 

どちらのプログラムも、コンストラクタ(string、double)が定義されていない同じ問題があります。このエラーはどうすればよいですか?私は本当に助けが必要です。

+0

それはあなたが真である、そのようなコンストラクタを作成していないことを意味します。 – Mordechai

+0

BTWのコピーコンストラクタは '公共の靴(靴その他)'を意味します – Mordechai

答えて

0

それはあなたがこのパラメータでコンストラクタを追加する必要があることを意味:

//Constructor 
    public Shoes (String brand, double size) 
    { 
     this.brand = brand; 
     this.size = size; 
    } 
+0

wow ..私はちょうど間違っていたのを理解するのに1日を費やしましたが..ありがとうございました。 –

関連する問題