2017-10-28 77 views
1

我正在运行一个名为mycatmychoice的项目正在运行但未显示。我知道我错过了一些东西,但不知道是什么。任何意见是极大的赞赏。这是一个较大项目的一小部分,但我需要先让这部分工作。我没有收到任何错误,但输出不显示。项目正在运行但未显示

package mycatmychoice; 


public final class Mycatmychoice { 


    public static void main(String[] args) { 

    } 
    //variables 
    private String name; 
    private String breed; 
    private String gender; 
    private String color; 
    private int age; 
    public String introducecat; 

    //constructor 
    public Mycatmychoice(String breed, String name, String gender, String color, int age) { 
     this.breed = breed; 
     this.breed = name; 
     this.gender = gender; 
     this.color = color; 
     this.age = age; 
    } 


//Returns the value of name 
    public String getname() { 
     return name; 
    } 

    //Sets the name variable. 
    public void setname(String name) { 
     this.name = name; 
    } 

    //Returns the value of breed 
    public String getbreed() { 
     return breed; 
    } 

    //Sets the breed variable. 
    public void setbreed(String breed) { 
     this.breed = breed; 
    } 

    //Returns the value of gender 
    public String getgender() { 
     return gender; 
    } 

    //Sets the gender variable. 
    public void setgender(String gender) { 
     this.gender = gender; 
    } 

//Returns the value of color 
    public String getcolor() { 
     return color; 
    } 

//Sets the color variable. 
    public void setcolor(String color) { 
     this.color = color; 
    } 

//Returns the value of age 
    public int getage() { 
     return age; 
    } 

    //Sets the age variable. 
    public void setage(int age) { 
     this.age = age; 
    } 

    public void introducecat() { 
     System.out.printf("Say hi to %s who is a %d year old %s %s %s cat \n", getname(), getage(), getgender(), getcolor(), getbreed()); 
    } 
} 
+0

在main方法中需要一些语句。 – laune

+0

什么样的声明?我是一名初学者。 – Shelly

回答

1

更改main()方法包括本 -

public static void main(String[] args) { 
    Mycatmychoice cat = new Mycatmychoice("a", "b", "c", "d", 4); 
    cat.introducecat(); 
    } 

然后运行该程序,并查看输出。

此外,在构造函数中,你可能要在第二行,因为这 - 而不是

this.name = name; 

-

this.breed = name; 

下面是对main()方法好documentation。将其视为您可以在其中启动其他方法的源代码 -

主要方法与C和C++中的主要函数类似;它是您的应用程序的入口点,随后将调用您的程序所需的所有其他方法。

+0

谢谢,这正是我需要的 – Shelly

0

如果你想启动你的程序,那么main()是一个起点。你将需要实例化类的一个对象,调用getters和setter,然后调用display方法。

但是,更重要的是读了一本关于Java的书。

相关问题