2015-05-14 1 views
0

Я не могу понять, почему он дает мне код ошибки no suitable constructor found for.Ошибки конструктора (фактические и формальные списки аргументов различаются по длине)?

RegularPie(String,String,String,String,String,String,Double) 
super(theName, theCrust, theSize, theSauce, theCheese, theTopping, thePrice); 
^ 
constructor RegularPie.RegularPie(String,String,String,String,String) is not applicable 
(actual and formal argument lists differ in length) 
constructor RegularPie.RegularPie() is not applicable 
(actual and formal argument lists differ in length) 
Process completed. 

Что-то не так?

public class RegularPie 
{ 

    private String name; 
    private String size; 
    private String crust; 
    private String sauce; 
    private String cheese; 


    public RegularPie() 
    { 
     name  = "regular pie"; 
     crust = "Hand- Tossed"; 
     size  = "medium"; 
     sauce = "marinara"; 
     cheese = "mozzarella"; 
    } 

    public RegularPie(String theName, String theCrust, String theSize, String theSauce, String theCheese) 
    { 
     if(theName ==null ||theCrust ==null ||theSize ==null ||theSauce ==null ||theCheese ==null) 
     { 
      System.out.println("Pizza not created"); 
      System.exit(0); 
     } 
     name  = theName; 
     crust = theCrust; 
     size  = theSize; 
     sauce = theSauce; 
     cheese = theCheese; 

    } 

    public String getName() 
    { 
     return name; 
    } 
     public String getCrust() 
    { 
     return crust; 
    } 
     public String getSize() 
    { 
     return size; 
    } 
     public String getSauce() 
    { 
     return sauce; 
    } 
     public String getCheese() 
    { 
     return cheese; 
    } 
    public void setName(String newName) 
    { 
     if (newName == null) 
     { 
      System.out.println("Error with name"); 
      System.exit(0); 
     } 
     else 
     { 
      name = newName; 
     } 
    } 
    public void setCrust(String newCrust) 
    { 
     if (newCrust == null) 
     { 
      System.out.println("Error with crust"); 
      System.exit(0); 
     } 
     else 
     { 
      crust = newCrust; 
     } 
    } 
    public void setSize(String newSize) 
    { 
     if (newSize == null) 
     { 
      System.out.println("Error with size"); 
      System.exit(0); 
     } 
     else 
     { 
      size = newSize; 
     } 
    } 
    public void setSauce(String newSauce) 
    { 
     if (newSauce == null) 
     { 
      System.out.println("Error with suace"); 
      System.exit(0); 
     } 
     else 
     { 
      sauce = newSauce; 
     } 
    } 
    public void setCheese(String newCheese) 
    { 
     if (newCheese == null) 
     { 
      System.out.println("Error with topping"); 
      System.exit(0); 
     } 
     else 
     { 
      cheese = newCheese; 
     } 
    } 

    public String toString() 
    { 
     return("You order the " + name + " pizza, that has a " + crust + " crust, a standard " + size + " size, a " + sauce +" sauce, and a " + cheese + " topping."); 
    } 

    public boolean equals(RegularPie otherRegularPie) 
    { 
     return (name.equals(otherRegularPie.name)&&crust.equals(otherRegularPie.crust)&&size.equals(otherRegularPie.size)&&sauce.equals(otherRegularPie.sauce)&&cheese.equals(otherRegularPie.cheese)); 
    } 

    public class SpecialOne extends RegularPie 
    { 
     private String topping; 
     private double price; 

    public SpecialOne() 
    { 
     super(); 
     topping = ""; 
     price = 0; 
    } 

    public SpecialOne(String theName, String theCrust, String theSize, String theSauce, String theCheese, String theTopping, Double thePrice) 
    { 
     super(theName, theCrust, theSize, theSauce, theCheese, theTopping, thePrice); 
     topping = theTopping; 
     price = thePrice; 
    } 

    public SpecialOne(SpecialOne originalObject) 
    { 
     super(originalObject); 
     topping = originalObject.topping; 
     price = originalObject.price; 

    } 

    public String getTopping() 
    { 
     return topping; 
    } 
    public double getPrice() 
    { 
     return price; 
    } 
    public void setTopping(String newTopping) 
    { 
     topping = newTopping; 
    } 
    public void setPrice(Double newPrice) 
    { 
     price = newPrice; 
    } 

    } 
} 
+0

Вставьте код, в котором вы используете класс 'RegularPie', и получите ошибку. Что такое суперкласс 'RegularPie'? – pmichna

+0

Обычный пирог должен быть супер – TMonster

ответ

0

При вызове super(), вы вызываете конструктор parrent в. Итак, SpecialOne, ссылающийся на super(), вызывает конструктор для RegularPie, но вы проезжаете семь Strings в этот конструктор, а RegularPie не имеет конструктора, который принимает семь Strings. Удалить theTopping, thePrice от super() позвонить по телефону SpecialOne. Вы устанавливаете их явно в конструкторе SpecialOne, так как они являются членами этого класса, а не базового.

Смежные вопросы