debug my program? it's in Java. At line 108, I get the error “The field Person.age is not visible”. It won’t launch.   This is what the output should look like: created Person [name: Fred Flintstone, age: 50] Duplicate entry: Person [name: Fred Flintsone, age: 50] created Student [major: Math, GPA: 3.1, name: Fred Flintstone, age: 50] created Student [major: politics, GPA: 3.1, name: George, age: 21] Family array full. Skipping: Student [major: Physics, GPA: 2.5, name: Jim, age: 21] Family array full. Skipping: person [name: Robert, age: 10] Family array full. Skipping: Person [name: Clement, age: 32] *****family listing: Person [name: Fred Flintstone, age: 50] Student [major: Math, GPA: 3.1, name: Fred Flintsone, age: 50] Person [name: Wilma Flintstone, age: 48] Student [major: Math, GPA: 3.1, name: Fred Flintstone, age: 50] Person [name: Wilma Flintstone, age: 48] Student [major: politics, GPA: 3.1, name: Georgie, age: 21] Student [major: Politics, GPA: 3.1, name: George, age: 21] Student [major: Geology, GPA: 2.9, name: John, age 18] Student [major: music, GPA: 3.2, name: Jane, age: 21] Student [major: Gymnastics, GPA: 4.0, name: Tarzan, age: 22]   below is my program:   package family;   //@SuppressWarnings("EqualsandHashcode") class Person { private String name; private int age; public Person() {   } public Person(String name, int age) { this.name = name; this.age = age;   } @Override public String toString() { return "Person [name: "+ name +", age: " + age + "]"; } @Override //@SuppressWarnings("SuspiciousIndentAfterControlStatement") public boolean equals(Object obj) { if(this == obj) return true; if (obj != null) { } else { 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; } } @SuppressWarnings("EqualsAndHashcode")   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 double getAge() { // return age; // } // public double setAge(double age) // { // this.age = age; // }   @Override public String toString() { return "Student [major: " + major + ", GPA" + gpa+ ", name: " + getName()+ ", age" + age + "]"; } @Override   @SuppressWarnings("SuspiciousIndentAfterControlStatement") 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.contentEquals(other.major)) return false; return true; } }   public class Family { private final 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 energy: "+p); return; }   }   if (numPersons != familyPersons.length) { familyPersons[numPersons++] = p; } else { System.out.println("Family array full. Skipping... " + p); } } private void printOutFamily() { for(int i = 0; i < numPersons; i++) { System.out.println(familyPersons[i]); } } @SuppressWarnings("empty-statement") 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, "Gymastics", 4.0)); f.addPerson(new Student("Jim", 21, "Physics", 2.5)); f.addPerson(new Person("Clemente", 32)); System.out.println("*******family listing: ***********");   f.printOutFamily(); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 

Question

hello! can you help me debug my program? it's in Java. At line 108, I get the error “The field Person.age is not visible”. It won’t launch.

 

This is what the output should look like:
created Person [name: Fred Flintstone, age: 50]

Duplicate entry: Person [name: Fred Flintsone, age: 50]

created Student [major: Math, GPA: 3.1, name: Fred Flintstone, age: 50]

created Student [major: politics, GPA: 3.1, name: George, age: 21]

Family array full. Skipping: Student [major: Physics, GPA: 2.5, name: Jim, age: 21]

Family array full. Skipping: person [name: Robert, age: 10]

Family array full. Skipping: Person [name: Clement, age: 32]

*****family listing:

Person [name: Fred Flintstone, age: 50]

Student [major: Math, GPA: 3.1, name: Fred Flintsone, age: 50]

Person [name: Wilma Flintstone, age: 48]

Student [major: Math, GPA: 3.1, name: Fred Flintstone, age: 50]

Person [name: Wilma Flintstone, age: 48]

Student [major: politics, GPA: 3.1, name: Georgie, age: 21]

Student [major: Politics, GPA: 3.1, name: George, age: 21]

Student [major: Geology, GPA: 2.9, name: John, age 18]

Student [major: music, GPA: 3.2, name: Jane, age: 21]

Student [major: Gymnastics, GPA: 4.0, name: Tarzan, age: 22]

 

below is my program:

 

package family;

 

//@SuppressWarnings("EqualsandHashcode")

class Person {

private String name;

private int age;

public Person() {

 

}

public Person(String name, int age)

{

this.name = name;

this.age = age;

 

}

@Override

public String toString()

{

return "Person [name: "+ name +", age: " + age + "]";

}

@Override

//@SuppressWarnings("SuspiciousIndentAfterControlStatement")

public boolean equals(Object obj)

{

if(this == obj)

return true;

if (obj != null) {

} else {

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;

}

}

@SuppressWarnings("EqualsAndHashcode")

 

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 double getAge() {

// return age;

// }

// public double setAge(double age)

// {

// this.age = age;

// }

 

@Override

public String toString()

{

return "Student [major: " + major + ", GPA" + gpa+ ", name: " + getName()+ ", age" + age + "]";

}

@Override

 

@SuppressWarnings("SuspiciousIndentAfterControlStatement")

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.contentEquals(other.major))

return false;

return true;

}

}

 

public class Family

{

private final 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 energy: "+p);

return;

}

 

}

 

if (numPersons != familyPersons.length)

{

familyPersons[numPersons++] = p;

}

else

{

System.out.println("Family array full. Skipping... " + p);

}

}

private void printOutFamily()

{

for(int i = 0; i < numPersons; i++)

{

System.out.println(familyPersons[i]);

}

}

@SuppressWarnings("empty-statement")

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, "Gymastics", 4.0));

f.addPerson(new Student("Jim", 21, "Physics", 2.5));

f.addPerson(new Person("Clemente", 32));

System.out.println("*******family listing: ***********");

 

f.printOutFamily();

}

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education