public class PetShopDemo01{
public static void main(String args[]){
PetShop ps=new PetShop(5);
ps.add(new Cat("波斯猫","纯色",2));
ps.add(new Cat("大花猫","花色",2));
ps.add(new Cat("黑猫警长","黑色",2));
ps.add(new Dog("大黄狗","黄色",2));
ps.add(new Dog("哈巴狗","黑白色",2));
ps.add(new Dog("流浪狗","花色",2));
print(ps.search("黑"));
}
public static void print(Pet p[]){
for(int i=0;i<p.length;i++){
if(p[i]!=null){
System.out.println(p[i].getName()+" , "+p[i].getColor()+
" , "+p[i].getAge());
}
}
}
}
它说我这个地方进行语法解析时已达到文件结尾,找了半天,就是没找到哪个括号不对,求大家帮我找找!!
出错提示是在最后一个括号那,说进行语法解析时已达到文件结尾,会不会是别的错误啊??
public static void main(String args[]){
PetShop ps=new PetShop(5);
ps.add(new Cat("波斯猫","纯色",2));
ps.add(new Cat("大花猫","花色",2));
ps.add(new Cat("黑猫警长","黑色",2));
ps.add(new Dog("大黄狗","黄色",2));
ps.add(new Dog("哈巴狗","黑白色",2));
ps.add(new Dog("流浪狗","花色",2));
print(ps.search("黑"));
}
public static void print(Pet p[]){
for(int i=0;i<p.length;i++){
if(p[i]!=null){
System.out.println(p[i].getName()+" , "+p[i].getColor()+
" , "+p[i].getAge());
}
}
}
}
它说我这个地方进行语法解析时已达到文件结尾,找了半天,就是没找到哪个括号不对,求大家帮我找找!!
出错提示是在最后一个括号那,说进行语法解析时已达到文件结尾,会不会是别的错误啊??
试了一下,没有括号不匹配。
就是这里有问题
PetShop ps = new PetShop(5);
ps.add(new Cat("波斯猫", "纯色", 2));
ps.add(new Cat("大花猫", "花色", 2));
ps.add(new Cat("黑猫警长", "黑色", 2));
ps.add(new Dog("大黄狗", "黄色", 2));
ps.add(new Dog("哈巴狗", "黑白色", 2));
ps.add(new Dog("流浪狗", "花色", 2));
明明数组长度为5,你怎么加了6中宠物。
public xxx(){
public ooo(){
if(xxoo){
}
for(xx;00;oo){
} }
}
package projectTest;import java.util.ArrayList;
import java.util.List;public class PetShopDemo01 {
public static void main(String args[]) {
PetShop ps = new PetShop(5);
ps.add(new Cat("波斯猫", "纯色", 2));
ps.add(new Cat("大花猫", "花色", 2));
ps.add(new Cat("黑猫警长", "黑色", 2));
ps.add(new Dog("大黄狗", "黄色", 2));
ps.add(new Dog("哈巴狗", "黑白色", 2));
ps.add(new Dog("流浪狗", "花色", 2));
print(ps.search("黑"));
} public static void print(Pet[] p) {
for (int i = 0; i < p.length; i++) {
if (p[i] != null) {
System.out.println(p[i].getName() + " , " + p[i].getColor()
+ " , " + p[i].getAge());
}
}
}
}class Pet {
String name;
String color;
int age;
public Pet(){
} public Pet(String name, String color, int i) {
this.name = name;
this.color = color;
this.age = i;
} public String getName() {
return name;
} public int getAge() {
return age;
} public String getColor() { return color;
}}class Cat extends Pet {
public Cat(String name, String color, int i) {
super(name,color,i);
}
}class Dog extends Pet { public Dog(String name, String color, int i) {
super(name,color,i);
}
}class PetShop {
int MaxContent;
List<Pet> pets;
static int index = 0; public PetShop(int i) {
MaxContent = i;
pets = new ArrayList<Pet>();
} public Pet[] search(String string) {
List<Pet> plist = new ArrayList<Pet>();
for (Pet p : pets) {
if ((p.name.contains(string)) || (p.color.contains(string))) {
plist.add(p);
}
}
Pet[] temp = new Pet[plist.size()];
return plist.toArray(temp);
} public void add(Pet p) {
if (index < MaxContent) {
pets.add(p);
index++;
System.out.println(p + "已经添加到宠物店");
} else {
System.out.println("宠物店已经满");
}
}}