hello! can you help me debug my program? it's in Java. here are my errors: line 155: void is an invalid type for the variable printOutFamilyline 126: the method content(String) is undefined for the type String here is my program: package family; class Person { private String name; private int age; public Person() { } public Person(String name, int age) { this.name = name; this.age = age; } public String toString() { return "Person [name: "+ name + ", age: " + age+ "]"; } @Override public boolean equals(Object obj) { if(this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Person other = (Person) obj; if(age != other.age)return false; if(name == null) { if(other.name !=null) return false; } else if (!name.contentEquals(other.name)) return false; return true; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } class Student extends Person { private String major; private double gpa; public Student(String name, int age, String major, double gpa) { super(name, age); this.major = major; this.gpa = gpa; } public Student() { } public String getMajor() { return major; } public void setMajor(String major) { this.major=major; } public double getGpa() { return gpa; } public void setGpa(double gpa) { this.gpa = gpa; } public String toString() { return "Student [major: "+ major +", GPA: " +gpa + ", name: "+ getName() + ", age: " + getAge() + "]"; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; Student other = (Student) obj; if(gpa != other.gpa) return false; if (major == null) { if(other.major != null) return false; } else if (!major.content(other.major)) return false; return true; } } public class Family { private Person familyPersons[]; private int numPersons = 0; public Family(int num) { familyPersons = new Person[num]; } private void addPerson(Person p) { for (int i =0; i < numPersons; i++) { if(familyPersons[i].equals(p)) { System.out.println("Duplicate entry: "+p); return; } } if (numPersons != familyPersons.length) { familyPersons[numPersons++] = p; } else { System.out.println("Famuly array full. Skippin: " +p); } } private void printOutFamily; { for(int i = 0; i < numPersons; i++) { System.out.println(familyPersons[i]); } } private void printOutFamily() { for(int i = 0; i < numPersons; i++) { System.out.println(familyPersons[i]); } } public static void main(String[] args) { Family f = new Family(8); Person fred = new Person("Fred Flintstone", 50); System.out.println("created " + fred); f.addPerson(fred);; f.addPerson(fred);; Student fredStudent = new Student("Fred Flintstone", 50, "Math", 3.1); System.out.println("created "+fredStudent); f.addPerson(fredStudent); Person wilma = new Person("Wilma Flintstone", 48); f.addPerson(wilma);; Student george = new Student("George", 21, "politics", 3.1); System.out.println("created " + george); f.addPerson(george); george.setName("Georgie"); f.addPerson(new Student("George", 21, "Politics", 3.1)); f.addPerson(new Student("John", 18, "Geology", 2.9)); f.addPerson(new Student("Jane", 21, "music", 3.2)); f.addPerson(new Student("Tarzan", 22, "Gymnastics", 4.0)); f.addPerson(new Student("Jim", 21, "Physics", 2.5)); f.addPerson(new Person("Robert", 18)); f.addPerson(new Person("Clemente", 32)); System.out.println("******** family listing: "); f.printOutFamily(); } }
hello! can you help me debug my program? it's in Java.
here are my errors:
line 155: void is an invalid type for the variable printOutFamily
line 126: the method content(String) is undefined for the type String
here is my program:
package family;
class Person {
private String name;
private int age;
public Person() {
}
public Person(String name, int age)
{
this.name = name;
this.age = age;
}
public String toString()
{
return "Person [name: "+ name + ", age: " + age+ "]";
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Person other = (Person) obj;
if(age != other.age)return false;
if(name == null) {
if(other.name !=null)
return false;
}
else if (!name.contentEquals(other.name))
return false;
return true;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
}
class Student extends Person {
private String major;
private double gpa;
public Student(String name, int age, String major, double gpa)
{
super(name, age);
this.major = major;
this.gpa = gpa;
}
public Student()
{
}
public String getMajor()
{
return major;
}
public void setMajor(String major)
{
this.major=major;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa)
{
this.gpa = gpa;
}
public String toString()
{
return "Student [major: "+ major +", GPA: " +gpa + ", name: "+ getName() + ", age: " + getAge() + "]";
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
Student other = (Student) obj;
if(gpa != other.gpa)
return false;
if (major == null)
{
if(other.major != null)
return false;
}
else if (!major.content(other.major))
return false;
return true;
}
}
public class Family
{
private Person familyPersons[];
private int numPersons = 0;
public Family(int num)
{
familyPersons = new Person[num];
}
private void addPerson(Person p)
{
for (int i =0; i < numPersons; i++)
{
if(familyPersons[i].equals(p))
{
System.out.println("Duplicate entry: "+p);
return;
}
}
if (numPersons != familyPersons.length)
{
familyPersons[numPersons++] = p;
}
else
{
System.out.println("Famuly array full. Skippin: " +p);
}
}
private void printOutFamily;
{
for(int i = 0; i < numPersons; i++)
{
System.out.println(familyPersons[i]);
}
}
private void printOutFamily()
{
for(int i = 0; i < numPersons; i++)
{
System.out.println(familyPersons[i]);
}
}
public static void main(String[] args) {
Family f = new Family(8);
Person fred = new Person("Fred Flintstone", 50);
System.out.println("created " + fred);
f.addPerson(fred);;
f.addPerson(fred);;
Student fredStudent = new Student("Fred Flintstone", 50, "Math", 3.1);
System.out.println("created "+fredStudent);
f.addPerson(fredStudent);
Person wilma = new Person("Wilma Flintstone", 48);
f.addPerson(wilma);;
Student george = new Student("George", 21, "politics", 3.1);
System.out.println("created " + george);
f.addPerson(george);
george.setName("Georgie");
f.addPerson(new Student("George", 21, "Politics", 3.1));
f.addPerson(new Student("John", 18, "Geology", 2.9));
f.addPerson(new Student("Jane", 21, "music", 3.2));
f.addPerson(new Student("Tarzan", 22, "Gymnastics", 4.0));
f.addPerson(new Student("Jim", 21, "Physics", 2.5));
f.addPerson(new Person("Robert", 18));
f.addPerson(new Person("Clemente", 32));
System.out.println("******** family listing: ");
f.printOutFamily();
}
}
Trending now
This is a popular solution!
Step by step
Solved in 8 steps with 9 images