到目前爲止我personClass一個personTester,我有以下幾點:我想寫一個personclass和Java中
package personclass;
public class Personclass {
private static boolean Personclass;
private int PersonCount;
public int getPersonCount()
{
return PersonCount;
}
private String FirstName;
private String LastName;
private int Age;
private Double Height;
private String Gender;
public Personclass(String foreName, String surName, int age, Double height, String gender)
{
FirstName = foreName;
LastName = surName;
Age = age;
Height = height;
Gender = gender;
}
private String getFirstName()
{
return FirstName;
}
private void setFirstName(String foreName)
{
this.FirstName = foreName;
}
private String getLastName()
{
return LastName;
}
private void setLastName(String surName)
{
this.LastName = surName;
}
private int getAge()
{
return Age;
}
private void setAge(int age)
{
this.Age = age;
}
private Double getHeight()
{
return Height;
}
private void setHeight(Double height)
{
this.Height = height;
}
private String getGender()
{
return Gender;
}
private void setGender(String gender)
{
this.Gender = gender;
}
/**
*
* @param FirstName
* @param LastName
* @param Age
* @param Height
* @param Gender
*/
public Personclass(String FirstName, String LastName, int Age, double Height, String Gender)
{
this.FirstName = FirstName;
this.LastName = LastName;
this.Age = Age;
this.Height = Height;
this.Gender = Gender;
++PersonCount;
}
/**
*
* @return
*/
@Override
public String toString()
{
return "Person[forename=" + getFirstName() + ", surname=" + getLastName() + ", age=" + getAge() + ", height=" + getHeight() +"m" + ", gender=" + getGender() +"]";
}
public String format()
{
return String.format("%10s %10s %10d %10.2f %10s", getFirstName() , getLastName() , getAge() , getHeight() , getGender());
}
public static void main(String[] args)
{
}
}
而對於我personTester,我有以下代碼:
package personclass;
public class PersonTester
{
public static void main(String[] args)
{
Person person1 = new Person("Joe","Smith",25,1.57,"Male");
Person person2 = new Person("Sain","Davies",18,1.73,"Female");
Person person3 = new Person("John","White",22,1.60,"Male");
Person person4 = new Person("Martin","Taylor",26, 1.54,"Male");
Person person5 = new Person("Jessica","Clarke",19,1.70,"Female");
System.out.println(person1.toString());
System.out.println(person2.toString());
System.out.println(person3.toString());
System.out.println(person4.toString());
System.out.println(person5.toString());
}
}
當我嘗試運行personTester時,遇到麻煩的事情是不打印任何東西。我如何去嘗試印出五個不同的人?
有兩種'main'方法。一個程序應該只有一個。嘗試刪除'Personclass.java'中的一個,或者在運行之前通過選擇類來顯式執行另一個。 –
添加合適的縮進 –
「Person」類在哪裏?我看到一個'Personclass'類和一個'PersonTester'類。 – rgettman